Global state — StoreProvider
When several components need to read or change the same state, wrap them in a StoreProvider and reach for useStore (reads) and useActions (writes). The action vocabulary is identical to the local hook.
Two sibling components below share one store. Clicking in Controls updates Display — no prop drilling, no callback wiring.
Display
0
Controls
The whole thing
Section titled “The whole thing”import { createSimpleStore, StoreProvider, useStore, useActions,} from '@input-actions/core';
const store = createSimpleStore({ count: 0 });
export default function App() { return ( <StoreProvider store={store}> <Display /> <Controls /> </StoreProvider> );}
function Display() { const count = useStore((s) => s.count); return <p>Count: {count}</p>;}
function Controls() { const actions = useActions(); return ( <> <button onClick={actions(['action/decrement', ['count']])}>−</button> <button onClick={actions(['action/increment', ['count']])}>+</button> <button onClick={actions(['action/increment', ['count'], 10])}>+10</button> <button onClick={actions(['action/reset'])}>Reset</button> </> );}What’s happening
Section titled “What’s happening”createSimpleStore(initial)builds the built-in adapter. It holds the state object you passed in.<StoreProvider store={store}>makes that store available to anything underneath via React context. One provider per tree.useStore((s) => s.count)reads a slice. The selector lets the hook subscribe to only that slice — re-renders happen when the slice’s value changes, not on every dispatch.useActions()returns the same handler factory as the local hook. Action tuples in, event handlers out.
Pick a backing adapter
Section titled “Pick a backing adapter”The built-in SimpleStore is fine for most apps. When you want time-travel, devtools, persistence, observability, or fine-grained reactivity, install one of the adapter packages — same <StoreProvider> and useStore / useActions on top.
pnpm add @input-actions/redux @reduxjs/toolkitimport { createReduxStoreSync } from '@input-actions/redux';const store = createReduxStoreSync({ count: 0 });pnpm add @input-actions/zustand zustandimport { createZustandStoreSync } from '@input-actions/zustand';const store = createZustandStoreSync({ count: 0 });pnpm add @input-actions/jotai jotaiimport { createJotaiStoreSync } from '@input-actions/jotai';const store = createJotaiStoreSync({ count: 0 });pnpm add @input-actions/mobx mobximport { createMobxStoreSync } from '@input-actions/mobx';const store = createMobxStoreSync({ count: 0 });pnpm add @input-actions/thi-ng @thi.ng/atomimport { createThingStoreSync } from '@input-actions/thi-ng';const store = createThingStoreSync({ count: 0 });// built-in undo/redo via store.undo() / store.redo()All adapters expose the same Store interface. Components don’t change when you swap backends — the action vocabulary is the contract.
Async + state machines come for free
Section titled “Async + state machines come for free”useActions accepts every action variant, including async ('action/async-prevent', etc.) and state-machine actions ('machine/transition', etc.). When you’re ready, register asyncHandlers and stateMachines on the same StoreProvider:
<StoreProvider store={store} asyncHandlers={{ submit: submitForm }} stateMachines={[checkoutMachine]}> …</StoreProvider>The full chat example exercises both layers; see the chat example.
- Action bindings quickstart — same setup, but behaviour lives in a typed registry instead of inline in JSX.
- Actions as data — why every state change is a tuple instead of a callback.