I've created a small example to show my problem.
import React, { useRef, useState } from "react";
export default function App() {
const renderCount = ++useRef(0).current;
const [, setValue] = useState(1);
console.log("Render count", renderCount);
const reRender = () => {
setValue((prev) => prev + 1);
};
return <button onClick={reRender}>Render</button>;
}
When I click the button 3 times the console output looks like this:
Render count 1
Render count 2
Render count 4
Render count 6
I would've expected the following:
Render count 1
Render count 2
Render count 3
Why doesn't it display each render count if it renders 6 times? And why does it render 6 times instead of 3 times?