When to use useState initial value as function?
You use it when you want the computation of that initial state to happen only once. Because if you use an expression instead say: const [state, setState] = useState(compute()); React saves the initial result of compute() once and ignores it on the next renders. But the compute function is still called on each render. This … Read more