Zustand middleware for integrating XState state machines into a global Zustand store. Currently at version 3.0.1, this package is designed to work seamlessly with XState v5 and Zustand v4, ensuring compatibility with their latest APIs and features. It provides a straightforward mechanism to create a Zustand store from an XState machine, exposing the machine's current `state`, the `send` event function, and the underlying `actor` for component consumption. This enables developers to leverage Zustand's reactive state management and selector capabilities to optimize re-renders while benefiting from XState's robust state orchestration. The middleware also allows passing actor options, such as `devTools`, directly to the XState actor, enhancing debugging and development workflows. While specific release cadences aren't explicitly stated, its alignment with major versions of its peer dependencies suggests active maintenance in response to their evolution.
npm install zustand-middleware-xstateVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating an XState machine, integrating it into a Zustand store with the middleware, and accessing state and send function.
Ensure your project uses `xstate@^5.15.0` and `zustand@^4.1.4` (or compatible versions) by upgrading your `package.json` dependencies and running `npm install`.
Refactor your XState machine definitions to use `setup({ ... }).createMachine({ ... })` as shown in the XState v5 documentation and the quickstart example.Use `import create from 'zustand'` instead of `import { create } from 'zustand'` for Zustand v4 and newer.Always pass the result of `setup({ ... }).createMachine({ ... })` to the `xstate` middleware function.Change `import { create } from 'zustand'` to `import create from 'zustand'`.Ensure your XState machine is created using `const machine = setup({ ... }).createMachine({ ... });` before passing `machine` to `xstate(machine)`.Verify that `xstate` (v5+) and `zustand` (v4+) are correctly installed and that the machine passed to the middleware is a valid XState v5 machine instance. Check console for earlier initialization errors.