Created
January 1, 2023 12:08
-
-
Save kivircik-parantez/1740e05aa36d2c320c79868b941fa795 to your computer and use it in GitHub Desktop.
Fetch Data and Clean Steal Response
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 SearchResults({ query }) { | |
const [results, setResults] = useState([]); | |
const [page, setPage] = useState(1); | |
useEffect(() => { | |
let ignore = false; | |
fetchResults(query, page).then(json => { | |
if (!ignore) { | |
setResults(json); | |
} | |
}); | |
return () => { | |
ignore = true; | |
}; | |
}, [query, page]); | |
function handleNextPageClick() { | |
setPage(page + 1); | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment