Last active
June 21, 2020 04:50
-
-
Save simbathesailor/43c67b031a14297c19bbe7e21d9f4c76 to your computer and use it in GitHub Desktop.
controlled-component-with-hooks1.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SearchAndResultView({ search, setSearch, result }) { | |
return ( | |
<Modal> | |
<SearchBox search={search} setSearch={setSearch} /> | |
<ResultContainer result={result} /> | |
</Modal> | |
); | |
} | |
function AnyofyourComponent() { | |
const [search, setSearch] = React.useState(""); | |
const [result, setResult] = React.useState([]); | |
async function onSearch(e) { | |
const value = e.target.value; | |
setSearch(value); | |
// do some API call | |
const res = await fetch("https://random-api"); | |
setResult(res.data); | |
} | |
return ( | |
<SearchAndResultView | |
search={search} | |
setSearch={setSearch} | |
result={result} | |
/> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment