Created
March 2, 2020 11:09
-
-
Save jwchang0206/16c15e21f5e66bd324e30c7b7e5c3e48 to your computer and use it in GitHub Desktop.
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
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