pi-mono/packages/chord/src/react
Mario Zechner d7a988d18d feat(chord): a call's answer follows its state
Before a provider sends or forwards a call's result or error, it sends the origin's
waiting state, past the window if it is full, so a resolved call's changes are
applied on the page. TuiScope.optimistic shows a value while calls are pending; the
guide shows useOptimistic over a Chord reference; example 63.
2026-11-05 10:45:40 +00:00
..
hooks.ts feat(chord): messages and languages in the app kit (i18n) 2026-11-03 20:25:53 +00:00
index.ts feat(chord): messages and languages in the app kit (i18n) 2026-11-03 20:25:53 +00:00
README.md feat(chord): a call's answer follows its state 2026-11-05 10:45:40 +00:00
stores.ts feat(chord): Chord v2 is the package's root 2026-11-02 22:36:55 +00:00

react

React bindings (slice 11 §3, decision "Slice 11, P7"): @earendil-works/chord/react; optional (React is an optional peer), non-React apps never load it. No components, no styling.

  • HostProvider({ host }), useHost().
  • useHold(Type, params): a reference held while the component is mounted, released on unmount, held again when its params change (compared by value); undefined on the first render.
  • useWatch(watchable): its current value (undefined while it has none), re-rendering on change (useSyncExternalStore over watchStore).
  • useRegistry(R): the registry's composed value; useRefState(ref): the reference's state.
  • useMessages(t): { t, locale }, a plugin's messages bound to the host's language (followed by startPage), re-rendering when the locale or a translation changes; before a language is followed, the first catalog.
  • usePageState(key, initial): useState's pair, the value kept by the page (its host's life) under key (surfaces/page-state.ts, shared with TuiScope.pageState), so a component remounted by a plugin reload keeps it.
  • Optimistic UI needs no hook of Chord's: React's useOptimistic and startTransition over a call. A call settles in the page after every change its answering host (and a host relaying its answer) committed before answering, so the optimistic value is replaced by the real one, never by the old (design §3, decision "A call's answer follows its state"; changes committed after the answer or on a host that does not relay it are not covered). The guide's "Optimistic UI" (docs/guide-plugins-hosts/book.md) shows it.
  • A component unmounted by a reload has not left (design §21): its releases are plain releases. A component of a reloaded plugin is a new function and remounts, its useState starting over: what must survive is page state.

Tests: test/node/react/ (stores.test.ts in Node, hooks.test.ts in a real browser); the page state alone in test/surfaces/page-state.test.ts.