github statelyai/xstate @xstate/store@3.9.0

17 days ago

Minor Changes

  • #5354 515cc31 Thanks @davidkpiano! - Add createStoreHook(…) function for React. Creates a store hook that returns [selectedValue, store] instead of managing store instances manually.

    const useCountStore = createStoreHook({
      context: { count: 0 },
      on: {
        inc: (ctx, event: { by: number }) => ({
          ...ctx,
          count: ctx.count + event.by
        })
      }
    });
    
    // Usage
    const [count, store] = useCountStore((s) => s.context.count);
    store.trigger.inc({ by: 3 });
    
    // Usage (no selector)
    const [snapshot, store] = useCountStore();

Don't miss a new xstate release

NewReleases is sending notifications on new releases.