export const Component = () => {
const [count, setCount] = useState<number>(0);
const renderCount = useRef<number>(0);
renderCount.current = renderCount.current + 1;
return (<>
<div>{`Rendered ${renderCount.current} times`}</div>
<button type="button" onClick={() => setCount(count + 1)}>{`Clicked ${renderCount.current} times`}</button>
</>);
}
I'd expect for clicking the button to cause one rerender, because the value of count
updates, and the UI has to rebuild itself. But it seems to cause two rerenders with every change. How/why is this happening?