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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Not at all, the
useStateMachine
implementation is actually built on top ofuseReducer
.I often just use
useState
oruseReducer
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 thestatus
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.