Skip to content

Instantly share code, notes, and snippets.

@kivircik-parantez
Created January 1, 2023 12:08
Show Gist options
  • Save kivircik-parantez/1740e05aa36d2c320c79868b941fa795 to your computer and use it in GitHub Desktop.
Save kivircik-parantez/1740e05aa36d2c320c79868b941fa795 to your computer and use it in GitHub Desktop.
Fetch Data and Clean Steal Response
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