Bug appears fixed in latest Canary version.
The issue describes a bug where `useEffectEvent` retains the first render value when used inside a `memo`-wrapped component. The maintainer suggests this was fixed in a recent PR and confirms the fix in the latest Canary release. No further action is needed unless the issue persists in the stable release.
useEffectEvent retains the first render value when it's used inside a component wrapped in memo()
React version: 19.2.0
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
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.
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.
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!