rfcs
rfcs copied to clipboard
RFC: Cancel async effects
This proposal proposes to
- Provide
AbortSignalwhen executing effects. - Provide a way to stop async effects automatically.
useEffect(function* () {
setLoading(true)
// React automatically stops if the deps array outdated.
setText(yield getData(props.id))
}, [props.id])
useEffect(signal => document.addEventListener('event', () => something(), { signal }))
I utilized a similar methodology within this repository and ended up here while delving into its history. Another notable benefit we now possess, as opposed to when this RFC was initially suggested, is our alignment with the using syntax in TypeScript 5.2 and upcoming ECMAScript versions. I don't believe there's currently a viable means of seamlessly integrating the using syntax with the existing useEffect approach.