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