3 ms·
Has anyone used XState here? What are its pros, cons, and gotchas? The idea of expressing application state as transitions in a state machine is appealing, and
by throwanem 6y ago
Has anyone used XState here? What are its pros, cons, and gotchas? The idea of expressing application state as transitions in a state machine is appealing, and I'd be curious to know how others have found it as I consider trying it out for myself.
- Swizec 6y agoXState is fantastic for isolated pieces of complex state. Like a UI widget with action driven changes or a user’s auth state or a bells-and-whistles API request. But it’s not a replacement for state management as such. Here’s an example where I refactored a complex usereducer+context to xstate https://swizec.com/blog/react-context-without-context-using-xstate-codewithswiz-14-15 https://swizec.com/blog/react-context-without-context-using-...
- FpUser 6y agoI do not use React but I used concepts / implementations of state machines extensively in my native applications (GUI and backend)
- blktiger 6y agoI would say that using switching from Redux to XState is a bit like switching from js to typescript. You get additional rigor but that can of course slow you down and force you to deal with potential issues you might not have otherwise encountered. One of the nice benefits of XState is you can read the machine definition to easily understand how the state flows over time.
- fabian2k 6y agoI haven't used it in production yet, but I found it very interesting when experimenting with it a bit. One part I especially liked was how natural async actions work in XState. You can just insert a function that returns a Promise and define which state transition happens on resolve or reject. With other state management libraries or native react state management this ended up in ad-hoc state machines anyway. Though for pure server-side state I found React Query to be a pretty good solution that covers this part well. I'm not using it yet, but playing around with it did convince me that thinking in state machines or state charts is very helpful the moment the UI gets a bit more complex.