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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay