DEV Community

Sachin
Sachin

Posted on

Hook guide:useReducer() in react

use Reducer similar the usestate but it managed the complex state like object have differnt value and also managed the state in imutiable way

const [state,dispatch]=useState(reducer,initialState)

in this hook deep dive
what is reducer
it is a function it describe how the state changed the based on action and take current state and action as input and return a new state

what is initialState
it is startng value of the state when comp. it render

what is state
current state value which is used in component

what is dispatch
a function call the action to the reducer which the update the state
Image description

Top comments (0)