mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
22 lines
372 B
Markdown
22 lines
372 B
Markdown
# `useObservable`
|
|
|
|
React state hook that tracks the latest value of an `Observable`.
|
|
|
|
|
|
## Usage
|
|
|
|
```jsx
|
|
import {useObservable} from 'react-use';
|
|
|
|
const counter$ = new BehaviorSubject(0);
|
|
const Demo = () => {
|
|
const value = useObservable(counter$, 0);
|
|
|
|
return (
|
|
<button onClick={() => counter$.next(value + 1)}>
|
|
Clicked {value} times
|
|
</button>
|
|
);
|
|
};
|
|
```
|