Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Cancel async effects #204

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Jack-Works
Copy link

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

@bglgwyng
Copy link

bglgwyng commented Sep 4, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants