Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 373 Bytes

useObservable.md

File metadata and controls

21 lines (15 loc) · 373 Bytes

useObservable

React state hook that tracks the latest value of an Observable.

用法

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>
  );
};