Limitations of useState
useState
is a great way to define a state, but it does have its limitations. The setter functions can grow too big if the logic gets complicated, plus you have to make sure that you return new items in every setter function using the spreading syntax. Also, if one state depends on another, you can end up writing tedious logic to make sure everything is correct in all of your dependencies.
When dealing with complex interactions, we need to define multiple pieces of states and managing logic can get out of control. We can prevent this state logic from getting too out of control through the use of useReducer
.