@react-logic/state
v0.1.2
Published
Signal primitives: `state`, `computedState`, `effect`, `batch`.
Readme
@react-logic/state
Signal primitives: state, computedState, effect, batch.
Part of react-logic. For the full toolkit in one install, use @react-logic/react-logic.
Install
npm install @react-logic/statePeer dependency: react@^18 || ^19. Pulls in @react-logic/di transitively for effect lifetime management.
Usage
import { state, computedState, effect, batch } from '@react-logic/state';
const count = state(0);
const doubled = computedState(() => count() * 2);
effect(() => console.log('count:', count(), 'doubled:', doubled()));
count(1); // → "count: 1 doubled: 2"
batch(() => {
count(2);
count(3); // both writes coalesce; effect fires once at end
});- Read with
s(), write withs(next). computedStateaccepts an optional input arg variant for derived signals parameterized at call time.effectreturns a disposer; cleanup is auto-tracked insideuseLogicand injection scopes.
See the project README for full docs and demos.
License
MIT
