Documentation
Docs
Introduction
Getting Started
Tutorial: build an app
Core Concepts
Routing
Server-Side Rendering
Mimir, state management
Pages & Layouts
API Routes
Styling & Theming
Building & Deploying
API Reference
Guides
Recipes
FAQ (use cases)
Reference , ekko:rune/mimir
State: atoms, selectors, hooks, the store, and SSR dehydration. Import:
See the Mimir chapter for the narrative.
atom(config) → Atom
| Field | Required | Notes |
|---|---|---|
key | yes | Globally unique string; identity for storage/hydration/persistence. |
default | yes | Initial value (throws if omitted). |
persist | no (default true) | Save to IndexedDB when a session is active. |
Returns a frozen definition (__brand: "atom"). Throws if key is missing/empty or default is absent.
selector(config) → Selector
Read-only derived state. get(api) reads atoms/selectors via api.get(x); every read becomes a tracked
dependency. Recomputes (and notifies) when a dependency changes. Circular dependencies throw
Mimir: circular selector dependency at '...'.
Hooks
| Hook | Returns | Subscribes? |
|---|---|---|
useAtom(atom) | [value, setValue] | yes |
useAtomValue(atomOrSelector) | value | yes |
useSetAtom(atom) | setValue | no (write-only) |
setValue accepts a value or an updater (prev) => next. Writes short-circuit when Object.is(prev, next).
useSetAtom accepts only atoms (not selectors).
The store , mimir
The singleton store instance.
| Method | Signature | Notes |
|---|---|---|
get | (atomOrSelector) → value | Computes selectors. |
set | (atom, valueOrUpdater) → void | Notifies subscribers + dependent selectors. |
reset | (atom) → void | Back to default. |
subscribe | (atomOrSelector, fn) → unsubscribe | fn(newValue) on change. |
snapshot | () → object | Plain { key: value } of all set values. |
session | (mode, opts?) → void | "none" | "ephemeral" | "domain"; opts.persistDelay. |
clearSession | () → void | Drop persisted state, reset persisted atoms, mode → none. |
hydrate | (atoms) → void | Bulk set plain { key: value }. |
initStore | (serverAtoms) → void | Directive-aware seed (__force/__merge); used during hydration. |
SSR dehydration , createStore()
Build the __atoms seed on the server with merge directives:
Return store.dehydrate() from ssr().__atoms. See Mimir → SSR & hydration.
Seed directive semantics (initStore)
| Entry shape | Behaviour |
|---|---|
value | Set the atom only if it has no value (fill). |
{ __force: true, __value } | Overwrite. |
{ __merge: true, __value } | Deep-merge into the existing object (or set if none). |
Sessions
| Mode | Scope |
|---|---|
"none" (default) | In-memory only. |
"ephemeral" | This browser tab/session (cleared on tab close). |
"domain" | The whole origin (across tabs and restarts). |
Under a session, persist: true atoms are written to IndexedDB (db mimir, store kv) with a debounced
flush (~100ms). The server communicates the mode via __sessionMode.
Server vs client
Both implementations expose the same surface. The client hooks drive React re-renders (subscribe →
setState) and add IndexedDB persistence; the server store is a one-shot used to produce a single render.
Write atoms once; they work in both.
Next: ekko:rune/seo.