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)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay