Use the useEnhancedReducer hook introduced here.

Then you will have something like.

const [state, dispatch, getState] = useEnahancedReducer(reducer, initState)

Because dispatch, getState will never change, you can pass it to some hook without adding them to the dependence list or store them somewhere else to call them from outside.

There is also version of useEnhancedReducer which supports adding middleware, in the same post.

Related Query

More Query from same tag