dai-shi / use-signals

An experimental React hook for TC39 signals
MIT License
319 stars 6 forks source link

use-signals

CI npm size discord

An experimental React hook for TC39 signals

Install

npm install use-signals

Usage

import { Signal, useSignal } from 'use-signals';

const counter = new Signal.State(0);

const Counter = () => {
  const count = useSignal(counter);
  const inc = () => counter.set(counter.get() + 1);
  return (
    <>
      <div>Count: {count}</div>
      <button type="button" onClick={inc}>
        +1
      </button>
    </>
  );
};

Examples

The examples folder contains working examples. You can run one of them with

PORT=8080 pnpm run examples:01_counter

and open http://localhost:8080 in your web browser.

You can also try them directly: 01 02

Tweets