4 ms·
For what it's worth, I've been working on a state machine library that's more deeply integrated into React: https://github.com/humaans/react-machine https://git
by kn8 6y ago
For what it's worth, I've been working on a state machine library that's more deeply integrated into React: https://github.com/humaans/react-machine https://github.com/humaans/react-machine.
It does a few things differently from XState / Robot bindings:
1. Use React's useReducer for state transitions and useEffect for applying the effects.
2. Allow reacting to component props (or machine context) and transitioning within the same render where props changed (achieved with a dispatch in the render body). This means the component's children get rendered with props and machine state that is in sync.
3. Separate machine's context (often component props) from machine's state. This reduces the number of unnecessary rerenders, while allowing your machine's reducers and effects to use up to date data and functions passed via props.
All in all, it's my exploration of how to more tightly integrate statecharts into React's render lifecycle and programming model.
- lewisl9029 6y agoThis looks almost exactly like what I was hoping for! Thank you for sharing! Love the fact that you've settled on mimicking Robot's one-way-to-do-things functional composition API (that's my preference as well), and have plans for maintaining compatibility with XState's ecosystem for visualizations (that's imo XState's killer feature over Robot). This really looks like it has the potential to offer the best of both XState and Robot _and_ offer a more seamless React integration! Will definitely be giving it a shot and keeping a close eye on future developments.