Migration overview & common pitfalls
This section helps you transition from common React state-management patterns to input-actions. It’s split by starting point — pick the guide that matches what you’re using today.
If you’re starting a new project, skip ahead to the Quickstart. This section is for code that already exists.
Common React state pitfalls
Section titled “Common React state pitfalls”A quick tour of patterns that input-actions is designed to remove. Each is a small, real situation; the fix column is the canonical input-actions shape.
1. Stale closures in callbacks
Section titled “1. Stale closures in callbacks”// Plain React — broken: increments stop being correct on rapid clicksconst [count, setCount] = useState(0);
<button onClick={() => setTimeout(() => setCount(count + 1), 500)}> +1 in 500ms</button>Click the button three times quickly: the count goes from 0 → 1 instead of 0 → 3. Each closure captures the count value at click time; later callbacks operate on stale data.
// input-actions: action data describes the operation, not the valueconst { state, actions } = useLocalActions({ count: 0 });
<button onClick={() => setTimeout(() => actions(['action/increment', ['count']])(), 500) }> +1 in 500ms</button>['action/increment', ['count']] says “add 1 to whatever count is at dispatch time.” No value capture. Three clicks become three increments.
2. Callback prop drilling
Section titled “2. Callback prop drilling”// Plain React — onChange passed through three levels just to reach the fieldfunction App() { const [user, setUser] = useState({ name: '', email: '' }); return <Page user={user} onUserChange={setUser} />;}function Page({ user, onUserChange }) { return <Form user={user} onUserChange={onUserChange} />; }function Form({ user, onUserChange }) { return ( <input value={user.name} onChange={(e) => onUserChange({ ...user, name: e.target.value }) } /> );}// input-actions: one provider at the top, useStore + useActions where the data is read or writtenconst store = createSimpleStore({ user: { name: '', email: '' } });
function App() { return ( <StoreProvider store={store}> <Page /> </StoreProvider> );}function Form() { const name = useStore((s) => s.user.name); const actions = useActions(); return ( <input value={name} onChange={actions(['action/save', ['user', 'name'], 'event/target.value'])} /> );}No prop drilling. Page doesn’t have to know Form exists or what it edits.
3. Forgotten preventDefault
Section titled “3. Forgotten preventDefault”// Plain React — easy to forget; submission accidentally reloads the page<form onSubmit={() => dispatch(submitForm())}>// input-actions: preventDefault is part of the action list, not the wrapper<form onSubmit={actions([ ['action/event', 'event/preventDefault'], ['action/async-prevent', 'submit', 'submitForm'],])}>The action’s intent and its side effect on the DOM event are both data. Nothing to forget.
4. useEffect chains coordinating async state
Section titled “4. useEffect chains coordinating async state”// Plain React — three booleans, two effects to keep them coherentconst [isLoading, setIsLoading] = useState(false);const [hasError, setHasError] = useState(false);const [data, setData] = useState(null);
useEffect(() => { if (!isLoading) return; fetchUser().then( (d) => { setData(d); setHasError(false); setIsLoading(false); }, () => { setHasError(true); setIsLoading(false); }, );}, [isLoading]);
useEffect(() => { if (data) trackAnalytics(data);}, [data]);Four pieces of state, two effects, easy to make incoherent.
// input-actions: one async action; lifecycle is in `_async`, follow-ups are datadispatch(['action/async', 'fetch-user', 'fetchUser', { strategy: 'prevent', onSuccess: [['action/push', ['analytics'], 'user-loaded']],}]);
// Read the lifecycle, no effects:const op = useAsyncOperation('fetch-user');// op.isLoading, op.hasError, op.dataNo state synchronisation. The library normalises the async lifecycle.
5. Re-render storms
Section titled “5. Re-render storms”// Plain React — every dispatch in a parent re-renders all childrenfunction Parent() { const [user, setUser] = useState({ name: '', email: '' }); const [count, setCount] = useState(0); // every setCount call re-renders Children that only depend on user return <> <Counter count={count} onIncrement={() => setCount(count + 1)} /> <UserDisplay user={user} /> </>;}// input-actions: per-component selectors via useStorefunction Counter() { const count = useStore((s) => s.count); // re-renders ONLY when count changes const actions = useActions(); return ( <button onClick={actions(['action/increment', ['count']])}> {count} </button> );}function UserDisplay() { const user = useStore((s) => s.user); // re-renders ONLY when user changes return <span>{user.name}</span>;}Sibling components don’t re-render each other. The selector defines the subscription.
6. Boolean state explosion for state machines
Section titled “6. Boolean state explosion for state machines”// Plain React — combinatorial booleans encode states implicitlyconst [isLoading, setIsLoading] = useState(false);const [isError, setIsError] = useState(false);const [hasData, setHasData] = useState(false);const [isStale, setIsStale] = useState(false);
// "Is the data definitely loaded and not refreshing?" → !isLoading && hasData && !isStale && !isErrorFour booleans = 16 combinations, most nonsensical. Bugs lurk in the unrepresented cases.
// input-actions: an explicit machine with named modesconst dataMachine = { name: 'data', initialState: 'idle', states: { idle: { allowedTransitions: ['loading'] }, loading: { allowedTransitions: ['ready', 'error'] }, ready: { allowedTransitions: ['refreshing'] }, refreshing: { allowedTransitions: ['ready', 'error'] }, error: { allowedTransitions: ['loading'] }, },};Five modes. The validator prevents impossible transitions. UI conditions read state.data.mode === 'ready', not a boolean salad.
7. No replayability / no time-travel
Section titled “7. No replayability / no time-travel”// Plain React — what happened that led to this bug? Good luck.const handleClick = () => { const next = computeSomething(state); setSomething(next);};The behaviour is a closure — invisible until it runs. To repro a bug you need the user’s full session.
// input-actions: every state change is a tuple. Log it, replay it, share it.const handleClick = actions(['action/save', ['something'], 'computed-value']);Action tuples are JSON-serialisable data. Add a logger, export a session, or — when paired with the Redux adapter — get time-travel debugging in DevTools for free.
What input-actions changes
Section titled “What input-actions changes”Across all the pitfalls above, the same shift is happening:
| Plain React | input-actions |
|---|---|
| Behaviour lives in closures | Behaviour lives in tuples |
| State synchronisation via effects | State derivation via selectors |
| Component-private state machines (booleans) | Explicit FSMs with validated transitions |
| Bug repro requires a video | Bug repro is a list of tuples |
ADR 0020 records the philosophy: every state change is data; components are visual building blocks; UI props are pure derivations from state.
Pick your starting point
Section titled “Pick your starting point”Already using Redux, Zustand, Jotai, MobX, or thi.ng?
Section titled “Already using Redux, Zustand, Jotai, MobX, or thi.ng?”You don’t need to migrate the underlying store — install the matching adapter and start dispatching input-actions tuples through your existing setup. The adapter packages keep the native API available (Redux DevTools, Jotai atoms, MobX autorun, thi.ng undo/redo).