Skip to content

Instantly share code, notes, and snippets.

@jgthms
Forked from bartcis/fetchOnClick.js
Created July 22, 2022 08:15
Show Gist options
  • Save jgthms/45eb39cda516c21cb7a866f45e894cd7 to your computer and use it in GitHub Desktop.
Save jgthms/45eb39cda516c21cb7a866f45e894cd7 to your computer and use it in GitHub Desktop.
Function to fetch and update abort functions
const fetchOnClick = async () => {
try {
abortFuncs.current.unshift(abortArticleRequest);
const newArticleRequest = await articleRequest;
const newArticle = await newArticleRequest.json();
setState([...state, newArticle]);
setArticleId(articleId +1);
} catch(e) {
console.error(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment