Static
The actions don’t depend on per-instance data. Same tuples every dispatch. The binding value is an action list.
A central place for every behaviour your app dispatches. Components reach for handlers by id with useBoundActions(id) and don’t construct action tuples inline. Optional — bindings coexist with the inline actions(...) pattern, mix freely.
The two panels below share one store. The counter uses a static binding; each todo row uses a factory binding that receives its own id as a param.
Counter (static binding)
0
Todos (factory binding)
import { createSimpleStore, defineBindings, StoreProvider, useBoundActions, useStore,} from '@input-actions/core';
const store = createSimpleStore({ count: 0, todos: { a: { id: 'a', text: 'Ship docs', done: true }, b: { id: 'b', text: 'Wire bindings quickstart', done: false }, },});
const bindings = defineBindings({ // Static — same actions every time. counter: { onIncrement: [['action/increment', ['count']]], onDecrement: [['action/decrement', ['count']]], onReset: [['action/save', ['count'], 0]], }, // Factory — receives per-instance params at click time. 'todo-item': { onToggle: (p: { id: string }) => [ ['action/toggle', ['todos', p.id, 'done']], ], },});
export default function App() { return ( <StoreProvider store={store} bindings={bindings}> <Counter /> <TodoList /> </StoreProvider> );}
function Counter() { const count = useStore((s) => s.count); const handlers = useBoundActions('counter'); return ( <> <p>Count: {count}</p> <button onClick={() => handlers.onDecrement?.()}>−</button> <button onClick={() => handlers.onIncrement?.()}>+</button> <button onClick={() => handlers.onReset?.()}>Reset</button> </> );}
function TodoRow({ todo }) { const handlers = useBoundActions('todo-item', { id: todo.id }); return ( <li> <input type="checkbox" checked={todo.done} onChange={() => handlers.onToggle?.()} /> {todo.text} </li> );}defineBindings(record) is a TypeScript inference helper. It returns its input unchanged so you can typeof appBindings later for your own typing.<StoreProvider bindings={...}> threads the registry through React context. Optional — providers without bindings work identically to before.useBoundActions(id, params?) looks up the entry for id and returns an object of event handlers. Static entries ignore params; factory entries receive them at dispatch time.Use whichever fits the binding:
Static
The actions don’t depend on per-instance data. Same tuples every dispatch. The binding value is an action list.
Factory
The actions depend on which instance triggered them — a todo id, a row index. The binding value is a function that receives those params and returns an action list.
Factories also receive the handler’s call arguments after params, which is the typed way to read a non-DOM callback’s value:
'filters.color': { onPick: (p: { field: string }, option: { value: string }) => [ ['action/save', ['filters', p.field], option.value], ],},const h = useBoundActions('filters.color', { field: 'color' });<ColorPicker onPick={h.onPick} /> // onPick(option) -> option.value savedStatic bindings can do the same with the event/arg placeholders.
Handlers keep their identity across renders while their inputs are unchanged, so they’re safe to pass to React.memo children. Params are compared one level deep, so an inline { id: todo.id } is fine without useMemo. A fresh nested object or array inside params ({ ids: [a, b] }) counts as a change. The handler set also changes when a machine-rooted entry’s mode changes. getBoundActions from useLocalActions follows the same rule.
Register your record once and every useBoundActions call is checked against it:
export const appBindings = defineBindings({ /* ... */ });
declare module '@input-actions/core' { interface Register { bindings: typeof appBindings; }}With that in place:
useBoundActions('feed.tabb'); // error: unknown iduseBoundActions('feed.tab'); // error: params requireduseBoundActions('feed.tab', { tab: 'nope' }); // error: not a valid tabuseBoundActions('search.input').onClickk; // error: no such handleruseBoundActions('wizard').onNext?.(); // machine-rooted: optional per modeParams are required when any of the entry’s factories takes them. A factory’s extra arguments become the handler’s signature. Without the Register block everything stays loose (string ids, unknown params), as before.
getBoundActions from useLocalActions needs no registration. It’s typed from the record you pass as the fourth argument.
Mixing is encouraged — the same component can call useBoundActions for one event and inline actions(...) for another. Both terminate in the same executor.
Bindings can also vary by current state-machine mode. The entry’s modes field maps each mode to its own event map; the hook re-renders when the machine transitions and exposes only the handlers defined for the current mode.
defineBindings({ 'wizard.controls': { machine: 'wizard', modes: { editing: { onPrimary: [['machine/transition', 'wizard', 'reviewing']], onCancel: [['action/reset']], }, reviewing: { onPrimary: [['machine/transition', 'wizard', 'submitted']], onBack: [['machine/transition', 'wizard', 'editing']], }, }, },});Mode names are plain strings, so the provider checks them when it mounts and whenever its bindings or machines change. It warns about a modes key that isn’t a state of the machine, and about a machine that isn’t configured. Either would otherwise just give you no handlers. A mode the entry leaves out, with no default, gets no handlers on purpose, and nothing is warned. To fail a test instead of logging, call validateBindings yourself:
import { StateMachineValidator, validateBindings } from '@input-actions/core';
test('bindings name real machine states', () => { const { problems } = validateBindings(appBindings, new StateMachineValidator(machines)); expect(problems).toEqual([]);});A concepts page on this lands soon — for now see the bindings example and ADR 0022.