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

Saving handler in useEffect() #50

Open
toschlog opened this issue Aug 18, 2021 · 1 comment
Open

Saving handler in useEffect() #50

toschlog opened this issue Aug 18, 2021 · 1 comment

Comments

@toschlog
Copy link

The current implementation contains this:

useEffect(() => {
    savedHandler.current = handler;
}, [handler]);

Is there any reason this has to be in a useEffect()? I would just do:

savedHandler.current = handler;

I would think that would be quicker to just store handler every time than having useEffect() check to see if it's changed.

Or am I missing something?

@Alexddsilva
Copy link

Its inside an effect because will happen only when handler changes.

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

No branches or pull requests

2 participants