Major Changes
-
#5512
063416dThanks @davidkpiano! - Modernize Store v4 package entrypoints.Use framework-specific packages such as
@xstate/store-reactand@xstate/store-solidinstead of@xstate/store/reactor@xstate/store/solid. The Store packages now publish ESM package entrypoints. -
#5512
063416dThanks @davidkpiano! - AddcreateStoreLogic(...)for reusable store definitions, and support creating stores from logic in framework hooks.const counterLogic = createStoreLogic({ context: (input: { initialCount: number }) => ({ count: input.initialCount }), on: { inc: (context) => ({ count: context.count + 1 }) } }); const store = useStore(counterLogic, { initialCount: 0 });
If a store logic requires input, the input argument is also required:
useStore(counterLogic, { initialCount: 0 });
Framework hooks also preserve schema-derived context, event, and emitted event types when creating stores from config objects.
Minor Changes
-
#5512
063416dThanks @davidkpiano! - Add reusable atom configs and framework atom-state helpers.createAtomConfig(...)creates an inert atom definition that can be instantiated with itscreateAtom(...)method or React/Preact/Vue/Solid'suseAtomState(...). These helpers return the current framework-native value and live atom instance, and also work with existing atom instances.const countConfig = createAtomConfig((input: { initialCount: number }) => { return input.initialCount; }); function Counter() { const [count, countAtom] = useAtomState(countConfig, { initialCount: 0 }); return ( <button onClick={() => countAtom.set((count) => count + 1)}> {count} </button> ); }