Skip to content
haragei-devPublic

About

Fine-grained reactive state for TypeScript, with framework-agnostic signals and React bindings.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

@haragei/signals

@haragei/signals is a lightweight, framework-agnostic TypeScript library for fine-grained reactive state.

It provides:

  • signals for reactive state with immutable reads
  • memos for derived state
  • effects for reactive side effects
  • actions for imperative async writes
  • resources for async derived state
  • stores for isolated reactive graphs

Installation

pnpm add @haragei/signals
import { action, batch, effect, memo, resource, signal, subscribe, untracked } from '@haragei/signals';

Quick Start

import { effect, memo, signal } from '@haragei/signals';

const [count, setCount] = signal(0);
const doubleCount = memo(() => count() * 2);

effect(() => {
    console.log(`${count()} x 2 = ${doubleCount()}`);
});

setCount(1);
setCount(2);

Usage with React

pnpm add @haragei/signals @haragei/react-signals react
import { useSignal, useSignalValue } from '@haragei/react-signals';

export function Counter() {
    const count = useSignal(0);
    const value = useSignalValue(count);

    return (
        <button type="button" onClick={() => count.update((current) => current + 1)}>
            Count: {value}
        </button>
    );
}

Learn More

Packages

License

MIT

See Also

About

Fine-grained reactive state for TypeScript, with framework-agnostic signals and React bindings.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages