React provides the useReducer
hook as an alternative to useState
for managing complex state logic.
Your task is to implement your own version of useReducer
from scratch.
Create a custom hook called useReducer
that:
reducer
function and an initialState
.dispatch
function.dispatch
is called with an action.The state update logic should follow the reducer pattern:
(state, action) => newState
Ensure that the component re-renders whenever the state changes.
Demonstrate your custom useReducer
by using it in the given simple counter component with increment
, decrement
, and reset
actions.