Bug: `useEffectEvent` retain the first render value when is used inside a component wrapped in `memo()`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 251k
- Forks
- 51.4k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 53
Description
useEffectEvent retains the first render value when it's used inside a component wrapped in memo()
React version: 19.2.0
Steps To Reproduce
Minimal repro:
import { useState, useEffectEvent, useEffect, memo } from "react";
function App() {
const [counter, setCounter] = useState(0);
const hello = useEffectEvent(() => {
console.log(counter);
});
useEffect(() => {
const id = setInterval(() => {
hello();
}, 1000);
return () => clearInterval(id);
}, []);
return (
<div>
<button onClick={() => setCounter(counter + 1)}>{counter}</button>
</div>
);
}
export default memo(App);
Link to code example:
https://codesandbox.io/p/sandbox/gj356q
The current behavior
If you click the button and increment the counter you always see 0 in the log. By removing the memo you will see the current counter value.
The expected behavior
See the latest counter value even if the component is wrapped in memo, since the documentation https://react.dev/reference/react/useEffectEvent does not describe any different behavior if component is wrapped in memo.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox and minimal reproduction using React 19.2.0, then compare the memo-wrapped and unwrapped cases while observing the interval log. The issue is resolved when the memo-wrapped component logs the latest counter value rather than retaining 0.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100