Simple global state for React.
Get started | Documentation | Quickstart
Features
- Tiny, with no runtime dependencies
- State persistence with session storage by default
- Selectors to limit re-renders
Install
npm install little-state-machineQuickstart
import { createStore, useStateMachine } from 'little-state-machine';
createStore({ count: 0 });
function increment(state) {
return { ...state, count: state.count + 1 };
}
function Counter() {
const { actions, state } = useStateMachine({ actions: { increment } });
return <button onClick={() => actions.increment()}>{state.count}</button>;
}Read the documentation for options, selectors, and TypeScript setup.