Skip to content

Instantly share code, notes, and snippets.

@jwchang0206
Created March 2, 2020 11:09
Show Gist options
  • Save jwchang0206/16c15e21f5e66bd324e30c7b7e5c3e48 to your computer and use it in GitHub Desktop.
Save jwchang0206/16c15e21f5e66bd324e30c7b7e5c3e48 to your computer and use it in GitHub Desktop.
import React, { useEffect, useRef } from 'react';
const Foo = () => {
const tokens = useRef([]);
useEffect(() => {
// Same as componentWillUnmount
return () => {
tokens.current.forEach(token => {
token.abort();
})
};
}, []);
const makeRequest = () => {
const controller = new AbortController();
tokens.current.push(controller);
// Use this signal for Fetch
dispatch('ACTION_REQUEST', { signal: controller.signal });
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment