Skip to content

fix: remove useEffectEvent functions from useEffect dependency arrays#960

Merged
sindresorhus merged 1 commit into
vadimdemedes:masterfrom
huww98:fix/remove-effect-event-from-deps
May 24, 2026
Merged

fix: remove useEffectEvent functions from useEffect dependency arrays#960
sindresorhus merged 1 commit into
vadimdemedes:masterfrom
huww98:fix/remove-effect-event-from-deps

Conversation

@huww98

@huww98 huww98 commented May 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Remove handleData from the useEffect dependency array in useInput
  • Remove handlePaste from the useEffect dependency array in usePaste

These were incorrectly added in #941. useEffectEvent return values intentionally have an unstable identity (they change every render), so including them in deps causes the effect to tear down and re-subscribe event listeners on every render — completely negating the purpose of useEffectEvent.

Per the React docs on useEffectEvent:

Effect Event functions do not have a stable identity. Their identity intentionally changes on every render.

The original commit (cfaebbb) that introduced useEffectEvent in these hooks correctly excluded them from the dependency arrays.

useEffectEvent return values intentionally have an unstable identity
(they change every render). Including them in useEffect deps causes
the effect to re-run on every render, tearing down and re-subscribing
event listeners each time — negating the purpose of useEffectEvent.

This was introduced incorrectly in vadimdemedes#941 when the exhaustive-deps lint
rule flagged them as missing dependencies. The React linter should
recognize useEffectEvent and suppress the warning, but it did not in
that case.
@sindresorhus sindresorhus merged commit 9d534f7 into vadimdemedes:master May 24, 2026
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants