concept initialization function in category react

This is an excerpt from Manning's book React Hooks in Action MEAP 04.
We saw in chapter 3 that we can generate the initial state for useState by passing a function to the hook. Similarly, with useReducer, as well as passing an initialization argument as the second argument, we can pass an initialization function as the third argument. The initialization function uses the initialization argument to generate the initial state, as shown in figure 4.6.
Figure 4.6 The initialization function for useReducer uses the initialization argument to generate the reducer’s initial state.
![]()
As usual, useReducer returns an array with two elements: the state and a dispatch function. On the first call, the state is the return value of the initialization function. On subsequent calls, it is the state at the time of the call.