Skip to content

Instantly share code, notes, and snippets.

@getify
Last active April 6, 2021 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getify/13d2138c7ba61bdca67c9d0014420efe to your computer and use it in GitHub Desktop.
Save getify/13d2138c7ba61bdca67c9d0014420efe to your computer and use it in GitHub Desktop.
function Article({ id }) {
const [article, setArticle] = useState(null);
useEffect(() => {
let cancelToken = new CAF.cancelToken();
let fetchData = CAF(function *fetchData(signal) {
const article = yield API.fetchArticle(id);
setArticle(article);
});
fetchData(cancelToken);
return () => {
cancelToken.abort();
};
}, [id]);
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment