Bug: `useEffectEvent` retain the first render value when is used inside a component wrapped in `memo()`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 251k
- Forks
- 51.4k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 53
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der verknüpften CodeSandbox und einer minimalen Reproduktion mit React 19.2.0. Vergleiche anschließend die memo-wrapped- und unwrapped-Fälle und beobachte dabei das Intervall-Log. Das Problem ist behoben, wenn die memo-wrapped-Komponente den neuesten Zählerwert protokolliert, anstatt 0 beizubehalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, react
- Bereich
- frontend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 58/100