Atomic State Management
@dathra/storeprovides a Recoil/Jotai-inspired atomic state management system
with store boundaries and AsyncLocalStorage support.
For exact signatures and snapshot details, see the Store API Reference.
atom()
Define atomic state units:
ts
import { atom } from "@dathra/store";
const countAtom = atom("count", 0);
const doubledAtom = atom("doubled", (get) => get(countAtom) * 2);createAtomStore()
Create a store instance with initial values:
ts
import { createAtomStore } from "@dathra/store";
const store = createAtomStore({
appId: "my-app",
values: [
[countAtom, 5],
],
});withStore()
Propagate a store through the component tree:
ts
import { withStore } from "@dathra/store";
const result = withStore(store, () => {
// Any signal/computed/effect inside here
// has access to the store context
return computeSomething();
});defineAtomStoreSnapshot()
Define a snapshot schema for serialization:
ts
import { defineAtomStoreSnapshot } from "@dathra/store";
const snapshot = defineAtomStoreSnapshot({
count: countAtom,
theme: themeAtom,
});Store Boundaries
Different subtrees can share a store or have isolated store boundaries. Useful for SSR where each request gets its own store context.