Licence
MIT
Version
0.1.3
Deps
0
Size
18 kB
Vulns
0
Weekly
0
state-context
Simple state-management with React Context API
Install
npm install state-context
Idea
state-context does state management for React. In terms of complexity it is located between using local state and Redux.
- With
state-contextit's very easy to migrate your component from local state to global state:
| Local state |
Global state with state-context
|
|
|
- It's useful for cases where Redux boilerplate would be an overhead (it still makes sense and is easy to decouple state management from UI layer).
| Redux | state-context |
|
actions.ts |
YES | NO |
actions.test.ts |
YES | NO |
reducer.ts |
YES | NO |
reducer.test.ts |
YES | NO |
side-effects.ts |
YES | NO |
side-effects.test.ts |
YES | NO |
container.tsx |
YES | YES |
container.test.tsx |
YES | YES |
ui-layer-component.tsx |
YES | YES |
ui-layer-component.test.tsx |
YES | YES |
- You can set up one global store or multiple shared-state containers.
- It's still deterministic as you can attach middleware and watch/undo/redo.
- You have TypeScript support out of the box.