Thanks ! and another example if we want to know how many times our Application renders with useState, we can't we get infinite loop cuz useState itself causes a re rendring, for that we can use useRef Hook
Thank you for the feedback! Great example Said Mounaim
Just to add; we can say; the state hook should be used for component re-rendering and the ref hook for information needed by event listeners and thus does not require component re-rendering.
Said Mounaim
Thanks ! and another example if we want to know how many times our Application renders with useState, we can't we get infinite loop cuz useState itself causes a re rendring, for that we can use useRef Hook
import { useState, useEffect, useRef } from "react"; function App() { const [inputValue, setInputValue] = useState(""); const count = useRef(0); useEffect(() => { count.current = count.current + 1; }); return ( <> <input type="text" value={inputValue} onChange={(e) => setInputValue(e.target.value)} /> <h1>Render Count: {count.current}</h1> </> ); }