useState is perfect for managing simple local state while and useReducer is go to alternative when the state logic becomes complex and deeply nested
How it Works:
Arguments:It accepts two arguments - reducer funtion and inital state.
Return: It return a pair in an array - current state and dispatch function.
dispatch function: dispatch function is used to update the state just like updater function in the useState.
Quick Syntax:const[state,dispatch] = useReducer(reducer,initial State).
Top comments (0)