I am new to react Hooks. Am trying to make use of useState
in my code. While I was using it I found a term "Lazy initial state"
https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
const [state, setState] = useState(() => {
const initialState = someExpensiveComputation(props);
return initialState;
});
But I am not able to think of any use case where this lazy initialising of state will be useful.
Like say my DOM is rendering and it needs the state
value, but my useState
has not initialised it yet! And say if you have rendered the DOM and the someExpensiveComputation
has finished, the DOM will re-render!