Coaction 4.2Immutable reactive state for TypeScript

State that follows your reads.

Components re-render only for the paths they read. Getters cache themselves. Every write becomes a transition you can undo, persist, sync, or hand to a Worker — behind a Zustand-style create().

npm install coaction @coaction/react

Works withReactVueAngularSvelteSolid

The Coaction octopus with four components on its arms. Each commit re-renders only the components that read the path it changed.

  • <Avatar />reads user.name1 render
  • <CartTotal />reads cart.total1 render
  • <AgeBadge />reads user.age1 render
  • <ItemList />reads cart.items1 render
Each commit reaches only the components that read what it changed.

The model

Immutable state. Signal-level reactivity. Transactional updates.

Coaction keeps React-style immutable snapshots and adds what they usually lack: fine-grained tracking on reads and reusable transitions on writes.

Immutable snapshots, natural writes

Write this.user.age += 1 inside set(). Mutative turns the draft into a new frozen snapshot, and untouched branches stay shared.

Signal-level precision on plain objects

Reads build a path graph on alien-signals. A reader of user.profile.name ignores a change to age, and your model needs no Signal<T> or Atom<T>.

Getters that cache themselves

A plain get total() is a cached computed value. Its dependencies are found automatically, and every reader shares one result.

Every write is a transition

set() produces the next snapshot and a commit, with patches when a feature needs them. Undo, persistence, sync and workers all build on it.

Live playground

Click an action. Count the re-renders.

This is the Coaction in this repository, running in your browser. Every cell is a component that counts its own renders: wrapped in observer() on the left, a plain useShop() that subscribes to the whole store on the right.

import { create } from '@coaction/react';

export const useShop = create((set) => ({
  user: { name: 'Ada', age: 36 },
  cart: { items: [{ name: 'Notebook', price: 12 }] },
  theme: 'light',

  get total() {
    return this.cart.items.reduce((sum, item) => sum + item.price, 0);
  },

  rename(name: string) {
    set(() => {
      this.user.name = name;
    });
  },
  birthday() {
    set(() => {
      this.user.age += 1;
    });
  },
  addItem(item: Item) {
    set(() => {
      this.cart.items.push(item);
    });
  },
  setTheme(theme: 'light' | 'dark') {
    set(() => {
      this.theme = theme;
    });
  }
}));
Run an action
Componentobserver()plain useShop()
<Avatar />Reads user.nameAda1Ada1
<AgeBadge />Reads user.age361361
<CartTotal />Reads total$121$121
<ItemList />Reads cart.itemsNotebook1Notebook1
Run an action to see which components re-render.

Numbers count each cell’s renders.

Less glue

The same counter, minus the selector plumbing.

A Coaction store reads like a Zustand store. What goes away is the code that only exists to stop extra renders: selectors, shallow equality and hand-written memoization.

Coactioncounter.tsx
import { create, observer } from '@coaction/react';

const useCounter = create((set) => ({
  count: 0,
  step: 1,

  // Cached automatically. Recomputed only when a dependency changes.
  get doubled() {
    return this.count * 2;
  },

  increment() {
    set(() => {
      this.count += this.step; // mutable-looking recipe, immutable next state
    });
  }
}));

const Counter = observer(() => {
  const store = useCounter(); // tracks only the fields this render reads

  return (
    <button onClick={store.increment}>
      {store.count} × 2 = {store.doubled}
    </button>
  );
});
Zustandcounter.tsx
import { create } from 'zustand';
import { useShallow } from 'zustand/react/shallow';
import { useMemo } from 'react';

const useCounter = create((set) => ({
  count: 0,
  step: 1,
  increment: () => set((s) => ({ count: s.count + s.step }))
}));

function Counter() {
  const { count, step } = useCounter(
    useShallow((s) => ({ count: s.count, step: s.step }))
  );
  const doubled = useMemo(() => count * 2, [count]);

  return (
    <button onClick={() => useCounter.getState().increment()}>
      {count} × 2 = {doubled}
    </button>
  );
}

Transitions

Every write is a transition you can reuse.

set() turns a recipe into the next snapshot and a commit. When a feature needs them, the commit carries patches and inverse patches, and undo, persistence, sync and shared runtimes all build on it instead of inventing their own write semantics.

set(() => { this.todos.push(todo) })
commitpatches + inverse patches
  • Reactivitycoaction

    Invalidates only the readers of what changed.

  • Undo / redo@coaction/history

    Steps back and forth with inverse patches.

  • Persistence@coaction/persist

    Saves commits; late hydration never overwrites new edits.

  • Local-first sync@coaction/sync

    A durable outbox, rebased over pulled remote changes.

  • Collaboration@coaction/yjs

    Binds the store to a Yjs document.

  • Shared runtimecoaction/shared

    One authority in a Worker, a mirror in every tab.

Sync backendsFetchCRUDSupabaseFirestoreTanStack QueryIndexedDB

Shared runtime

Start local. Move execution when you need to.

The same store source moves off the UI thread without a rewrite. A Worker becomes the authority, the page keeps a mirror for reads, and Coaction handles sequencing, patch sync and reconnects.

actionpatches

The worker owns the state. The page proxies actions and mirrors commits.

Worker
// worker.ts
import { create } from '@coaction/react/shared';
import { counter } from './counter';

create(counter);

// App.tsx
import { create } from '@coaction/react/shared';
import { counter } from './counter';

const worker = new Worker(new URL('./worker.ts', import.meta.url), {
  type: 'module'
});
const useCounter = create(counter, { worker });
  • The same counter source in every mode
  • Actions on a client return promises
  • Shared state is a strict JSON tree

Honest numbers

Fast where it counts. Upfront about the cost.

Coaction is built for immutable state, cached derived reads and fine-grained invalidation. It does not claim to win every microbenchmark, so here are both sides, measured with the repository’s own benchmarks.

CoactionZustand

84×faster than a selector that recomputes the total on every read

Reading derived state

1,000-item cart · ops/sec · higher is better

  • Zustand maintained total field112.1M
  • Coaction cached accessor getter66.1M
  • Coaction computed with manual deps33.8M
  • Zustand selector recompute787.5K

A hand-maintained total is faster still, because the application does the consistency work itself.

0.55×of Zustand’s selector throughput when every update is followed by a read

Update, then read

1,000-item cart · ops/sec · higher is better

  • Zustand immutable update + selector recompute88.1K
  • Coaction mutable update + cached getter48.5K
  • Coaction mutable update + manual deps48.3K

Not drawn: a hand-maintained Zustand total reaches 2,897,112 ops/sec, and replacing large objects drops Coaction to 169, so prefer a focused draft recipe for big collections.

All results as a table
Reading derived state
Caseops/secRME
Coaction cached accessor getter66,109,753±1.67%
Coaction computed with manual deps33,809,569±1.27%
Zustand selector recompute787,472±0.13%
Zustand maintained total field112,062,542±0.25%
Update, then read
Caseops/secRME
Coaction mutable update + cached getter48,480±0.81%
Coaction mutable update + manual deps48,318±0.66%
Coaction object replacement + cached getter169±4.15%
Zustand immutable update + selector recompute88,113±0.48%
Zustand immutable update + maintained total2,897,112±0.53%

Apple M1 Max, Node 24.16.0, runtime 12ae616, measured 2026-09-11. Single-machine numbers, not release floors; no React rendering is timed. Methodology Performance guide

Ecosystem

Bring your framework. Or keep your store.

The core is framework-agnostic. Bindings cover five frameworks, and whole-store adapters let Zustand, MobX, Redux Toolkit, Pinia, Jotai, Valtio and XState stores join the same model.

Support boundaries are documented, not implied: slices are core-only, and adapters bind a whole store. Support matrix

Fit

Coaction, Zustand or MobX?

Getters, this and automatic tracking are not new: MobX has shipped them for a decade. What is uncommon is having them on an immutable substrate, behind a Zustand-style create(), across five frameworks.

CoactionZustandMobX
ModelImmutable reactive stateMinimal external storeMutable observable graph
Render tracking without selectorsobserver(), or selectorsSelectors + useShallowobserver()
get value() and thisYesNoYes
Memoized derived valuesAcross independent readsuseMemo or reselectWhile observed, by default
Frozen snapshots, structural sharingYesVia Immer or MutativeMutable observables
Transition and patch substrateCore capabilityNot coremobx-state-tree
Worker or SharedWorker authorityBuilt-in shared runtimeApplication concernApplication concern
Local-first sync@coaction/syncExternalLibrary-dependent
Runtime costPays for immutable transitionsVery smallTuned for observable mutation

Start local. Grow into the rest.

Begin with one store and observer(). Add history, persistence, sync or a Worker when the application asks for them, without rewriting the model.

npm install coaction @coaction/react