rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

RFC: Cancel async effects

Open Jack-Works opened this issue 4 years ago • 1 comments

This proposal proposes to

  • Provide AbortSignal when 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 }))

View rendered RFC

Jack-Works avatar Sep 05 '21 15:09 Jack-Works

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.

bglgwyng avatar Sep 04 '23 12:09 bglgwyng