React observing

Counter

Counter

Here is an example of how to use react observing to build a simple counter.

1import { observe, useObserver } from 'react-observing'
2
3const counterStore = observe(0)
4
5const App = () => {
6 const [counter, setCounter] = useObserver(counterStore)
7
8 return (
9 <button onClick={() => setCounter(counter + 1)}>
10 Add +1 in {counter}
11 </button>
12 )
13}
Edit this page on GitHub