API reference
Kerros has one public function: createStore.
createStore(useStoreValue)
Turn a React Hook into a consumer Hook and Provider:
Type signature:
useStoreValue
useStoreValue is the Store implementation Hook. It may call other React Hooks and return the state and actions that should be shared:
It must follow the Rules of Hooks.
Define it as a top-level function named useXxxStoreValue. An anonymous initializer remains valid at runtime, but React Compiler infer mode does not automatically recognize and compile it as a Hook.
Return value
createStore returns two values:
useThemeis the Hook used by components or dependent StoresThemeProvideris the React component that creates and owns a Store instance
Domain names such as useTheme and ThemeProvider are recommended; repeating Store is optional.
Store Hook
The Store Hook requires an object-returning selector:
Kerros shallowly compares the returned object's top-level fields with Object.is. The component does not rerender for other Store updates while those selected fields stay equal.
Calling the Hook outside its matching Provider throws:
Provider props
All Provider props except children are passed to the Store Hook:
Every mounted Provider creates an independent Store instance.
React versions
React Compiler is optional.
Server rendering
Kerros supplies getServerSnapshot to useSyncExternalStore. The Provider's initial result is used for the server snapshot, and later values are published only after the Provider commits so consumers never observe an abandoned render.