create
Each framework subpath exports create. The overloads are shared conceptually even though return shapes differ by framework.
Plain state overload
create<T>(initialState: T | Store<T>): UseState<T>
const useSession = create({ user: null as null | { id: string } });Plain state exposes a writer named setState or a framework-native equivalent. React returns a tuple, Svelte exposes set, update, and setState; Vue, Solid, and Angular return objects with state and setState.
Reducer overload
create<T, Action extends { readonly type: string }>(
reduceFn: (state: T, action: Action) => T,
initialState: T | Store<T>,
): UseReducer<T, Action>Reducer state exposes dispatch or a writer returned by writeOnly() that accepts actions. Internally the action is converted to state by a middleware before continuing through the store pipeline.
Reusing an existing Store
import { Store } from '@ilokesto/store';
import { create } from '@ilokesto/state/react';
const store = new Store({ count: 0 });
const useCounter = create(store);Use an existing concrete Store<T> when multiple adapters or non-framework code need to share one source of truth. create accepts a value or Store<T>; it does not accept every structural StoreApi<T>.
Explicit bindings
Every framework subpath also exports bind(store: StoreApi<T>) and bindReducer(handle). Unlike create, bind accepts a structural store and never interprets its value or creates another store. bindReducer accepts the { store, dispatch } returned by root createReducer and does not register the reducer again.
See Vanilla state and binding for the contract and the migration guide for changes from the previous major.
Continue to Read and write APIs for readOnly() and writeOnly(), or choose the plain-state guide and reducer-state guide for task-oriented examples.