@xstate/store-react@2.1.0-alpha.1
Pre-release
Pre-release
·
3 commits
to main
since this release
Minor Changes
-
c57f80e: The
useStorehook now accepts aninspectoption 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>; }