DEV Community

Discussion on: React State Machine Hook

Collapse
 
droopytersen profile image
Andrew Petersen • Edited

Not at all, the useStateMachine implementation is actually built on top of useReducer.

I often just use useState or useReducer straight up, but occasionally I feel like a screen warrants a state machine because a state machine naturally solves for a lot of edge cases that require a lot of code to handle in a traditional useReducer.

For example, I shouldn't be able to submit the form if it is invalid. In a reducer I'd have to catch the submit action in a case statement, then check to make sure the status was not INVALID or DIRTY. A state machine automatically guards against this because only actions that are valid on the current status will be allowed to be triggered.