DEV Community


Discussion on: useState vs useReducer vs XState - Part 1: Modals

fredericbonnet profile image
Frédéric Bonnet

Great article, thanks! Another (major IMHO) argument in favor of useMachine over useState/useReducer is that the latter both depend on useEffect hooks that are a potential source of race conditions with asynchronous code. See for example:

Another big win for XState is that the machines are framework-agnostic. This means you can share the same your state logic across codebases (front/back/etc) and reuse the code in case your technical requirements change (e.g. front-end framework).

Self-documentation is the cherry on the cake.