React Performance: useState Lazy Initialization
Whenever you need to set the initial value of the state from a function that returns a value (see below), the function will get called at every re-render even though we only need it during the initial render.
const initialState = caluclateValue(props...
shauryakalia.com1 min read