@tjmc/global-state-manager
v0.0.60
Published
Global State Manager for React
Readme
@tjmc/global-state-manager
Global state manager for React with typed dispatch, selector-based subscriptions, and concurrent-safe bindings via modern React APIs.
Install
npm install @tjmc/global-state-managerQuick Example
import { StateStore } from '@tjmc/global-state-manager';
type GlobalState = { count: number };
type ActionPayloads = { setCount: number };
export const store = StateStore<GlobalState, ActionPayloads>({ count: 0 });
store.addReducer('setCount', (global, _actions, payload) => ({
...global,
count: payload,
}));
export const { setCount } = store.getDispatch();import { Provider, useGlobal } from '@tjmc/global-state-manager';
import { setCount } from './store';
function Counter() {
const count = useGlobal<GlobalState, number>((s) => s.count);
return (
<button onClick={() => setCount(count + 1, { reason: 'counter_click' })}>
{count}
</button>
);
}
<Provider store={store}>
<Counter />
</Provider>Documentation
- Docs index: docs/README.md
- Overview: docs/overview.md
- Getting started: docs/getting-started.md
- API: docs/api
- Recipes: docs/recipes
Build
npm run typescript
npm run buildTesting
npm run test
npm run test:store
npm run test:hooks
npm run test:hocLicense
MIT
