An experimental React hook for TC39 signals
npm install use-signals
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>
</>
);
};
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.