MCPcopy
hub / github.com/facebook/react / EffectWithState

Function EffectWithState

packages/react-devtools-shell/src/multi/right.js:20–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18}
19
20function EffectWithState() {
21 const [didMount, setDidMount] = useState(0);
22
23 const renderCountRef = useRef(0);
24 renderCountRef.current++;
25
26 useLayoutEffect(() => {
27 if (!didMount) {
28 setDidMount(true);
29 }
30 }, [didMount]);
31
32 return (
33 <ul>
34 <li>Rendered {renderCountRef.current} times</li>
35 {didMount && <li>Mounted!</li>}
36 </ul>
37 );
38}
39
40createRoot(createContainer()).render(<EffectWithState />);

Callers

nothing calls this directly

Calls 3

useStateFunction · 0.90
useRefFunction · 0.90
useLayoutEffectFunction · 0.90

Tested by

no test coverage detected