Skip to content

@xstate/store-react@2.1.0-alpha.1

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 03 Sep 21:11
· 3 commits to main since this release
2c4eeb4

Minor Changes

  • c57f80e: The useStore hook now accepts an inspect option for wiring up inspectors to component-local stores. The inspector is subscribed while the option is provided and stays stable across re-renders.

    import { useStore, useSelector } from '@xstate/store-react';
    import { createBrowserInspector } from '@statelyai/inspect';
    
    const inspector = createBrowserInspector();
    
    function Counter() {
      const store = useStore(
        {
          context: { count: 0 },
          on: {
            inc: (context) => ({ count: context.count + 1 })
          }
        },
        { inspect: inspector.inspect }
      );
      const count = useSelector(store, (s) => s.context.count);
    
      return <button onClick={() => store.send({ type: 'inc' })}>{count}</button>;
    }