React observing
Word counter
Word counter
Here is an example of how to use react observing to build a simple word counter.
1import { observe, transform, useObserver, useObserverValue } from 'react-observing'23const textStore = observe('')45const textSizeStore = transform(textStore, text => text.length)67const Counter = () => {8 const textSize = useObserverValue(textSizeStore)910 return <p>Length {textSize}</p>11}1213export const WordCounter = () => {14 const [text, setText] = useObserver(textStore)1516 return (17 <>18 <Counter />19 <input value={text} onChange={e => setText(e.target.value)} />20 </>21 )22}