Skip to content

SegmentState you can address.

A type-safe state engine for Octane and React built around structural paths, targeted subscriptions, and atomic commits.

Live storerunning Segment core
interactive
1const score = s.rows.at('beta').score
2store.observe(score, render)
3store.update(score, n => n + 1)
rows/alpha/score
12
rows/beta/score
27
rows/gamma/score
41
Choose an address to commitrows/beta/score

One model from state to transport

ts
import { createStore, segment } from 'segment-state';

const store = createStore({
	todos: segment({ title: '', completed: false }),
});

const completed = store.state.todos.at('docs').completed;

store.observe(completed, () => console.log(store.get(completed)));
store.set(completed, true, 'todo/complete');

A ref identifies state without exposing a mutable object. The same address can be observed by a component, written inside a transaction, serialized for hydration, or matched by an external port.

Measured behavior

Segment benchmark comparison against Valtio, Jotai, Redux, and Zustand

The benchmark suite prioritizes deterministic counts—callbacks woken, selector runs, and bookkeeping retained after churn—then measures write, memory, and mount costs in isolated processes. Timing and heap results are machine-specific.

Read the methodology and reproduce the run

Start with the shape of your data

The getting-started guide builds a store from plain values, shows how refs and transactions work, and introduces keyed segments. Continue with the state model or go directly to the advanced guide for resources, SSR, ports, and lifecycle guarantees. When you want to interact with the model first, open the browser playground.

Released under the MIT License.