Quick start
Install
Kerros is a standard npm package. npm, pnpm, Yarn, and Bun are all supported, as are React 17, React 18, and React 19.
Create a Store
In Kerros, any custom Hook can become shared state after being wrapped with createStore.
createStore returns an array. The first item is the Hook used by components, and the second is its Provider. Name them after the domain, such as useTask and TaskProvider; repeating Store in both names is optional.
The Store is still an ordinary React Hook, so it may use useState, useReducer, Context, SDK Hooks, or your own custom Hooks.
Keep the initializer as a top-level named Hook such as useTaskStoreValue. Anonymous initializers still run correctly, but React Compiler infer mode does not automatically compile them as Hooks.
Mount the Provider
TaskProvider is the state container. Only its descendants may call useTask, so mount it in the component tree first.
Calling useTask outside TaskProvider throws a clear error instead of silently reading the wrong Store instance.
Use the Store in a component
useTask requires a selector. Return an object containing only the fields this component needs.
Kerros shallowly compares the selector object's top-level fields. Updates to other Store fields do not rerender TaskList while tasks and finishTask remain unchanged.
The selector may stay inline and does not need useCallback.
useTaskis a React Hook, so the Rules of Hooks still apply.
Provider context and multiple instances
Every mounted TaskProvider creates an isolated Store instance.
Each TaskList reads its nearest TaskProvider. Their data is completely independent, just like two instances of the same React component.
Providers may also be nested. Descendants always use the nearest matching Provider.
Store dependencies
Real applications usually contain several small Stores. If tasks need the current account, call the Account Store directly inside the Task Store.
Mount the dependency Provider outside the dependent Provider:
Keep dependencies one-way. If the Task Store reads the Account Store, the Account Store must not read the Task Store back.
Pass props to a Provider
Provider props are passed to the Store Hook just like props passed to a React component.
When Provider props update, the Store Hook reruns normally and publishes its committed snapshot to consumers.
Root-level Stores
If a Store really serves the entire application, mount its Provider at the application root.
Kerros intentionally has no hidden global Store. Dependencies, initialization, and lifetime stay visible in the Provider tree, and tests never need to clear a module singleton.
Try it
This counter uses the same createStore + Provider + selector API:
Continue with Selectors and performance, Store composition, or Patterns.