@atolljs/react
v0.1.14
Published
React bindings — useObservable, useSharedValue, useTask
Downloads
791
Readme
@atolljs/react
React bindings for @atolljs/core — hooks that bind shared-memory fields and
worker tasks to component state over useSyncExternalStore. SSR-safe: field
reads return undefined until the contract binds on the client.
Install
npm install @atolljs/core @atolljs/reactUsage
import { useSharedValue, useTask } from '@atolljs/react';
import { counterMemory } from './counter.memory';
import { counter } from './counter';
export function App() {
const count = useSharedValue(counterMemory, 'count');
const increment = useTask(counter.increment); // client method → latest-wins task
return (
<button onClick={() => increment.run(1)}>
count: {count ?? '…'}
</button>
);
}API
useObservable(source)— subscribe to anyObservableValuesnapshot (task or field).useSharedValue(memory, key, select?, options?)— bind one shared-memory field to React state; optional selector +equalsslice updates so a component re-renders only when its slice changes.useTask(task | asyncFn)— bind anAsyncTask(or any async fn, e.g. aconnectWorkerclient method) to{ data, pending, settled, elapsedMs, error }plusrun/runOncetriggers.
Notes
counter.incrementis typed from the worker'sdefineWorkermethods — no task contract to declare.- Worker-hosted React trees (islands) live in the companion package
@atolljs/react-island.
