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

Function Counter

packages/react-reconciler/src/__tests__/useRef-test.internal.js:108–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

106
107 it('should return the same ref during re-renders', async () => {
108 function Counter() {
109 const ref = useRef('val');
110 const [count, setCount] = useState(0);
111 const [firstRef] = useState(ref);
112
113 if (firstRef !== ref) {
114 throw new Error('should never change');
115 }
116
117 if (count < 3) {
118 setCount(count + 1);
119 }
120
121 return <Text text={count} />;
122 }
123
124 ReactNoop.render(<Counter />);
125 await waitForAll([3]);

Callers

nothing calls this directly

Calls 2

useRefFunction · 0.50
useStateFunction · 0.50

Tested by

no test coverage detected