MCPcopy Create free account
hub / github.com/QuarkGluonPlasma/react-course-code / App

Function App

closure-trap/src/App3.tsx:3–24  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1import { useEffect, useState, useRef, useLayoutEffect } from 'react';
2
3function App() {
4 const [count, setCount] = useState(0);
5
6 const updateCount = () => {
7 setCount(count + 1);
8 };
9 const ref = useRef(updateCount);
10
11 useLayoutEffect(() => {
12 ref.current = updateCount;
13 });
14
15 useEffect(() => {
16 const timer = setInterval(() => ref.current(), 1000);
17
18 return () => {
19 clearInterval(timer);
20 }
21 }, []);
22
23 return <div>{count}</div>;
24}
25
26export default App;

Callers

nothing calls this directly

Calls 2

useStateFunction · 0.90
useEffectFunction · 0.90

Tested by

no test coverage detected