use-signals
v0.1.1
Published
An experimental React hook for TC39 signals
Downloads
88
Readme
use-signals
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 yarn run examples:01_counter
and open http://localhost:8080 in your web browser.
You can also try them in codesandbox.io: 01 02
Tweets
- https://twitter.com/dai_shi/status/1778085922770497940