The useReducer Hook is similar to the useState Hook. It allows for custom state logic. If you find yourself keeping track of multiple pieces of state that rely on complex logic, useReducer may be useful.
The useReducer Hook accepts two arguments.
reducer function contains your custom state logic and the
initialStatecan be a simple value but generally will contain an object.
useReducer Hook returns the current
Here is an example of
useReducer in a counter app: