main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
443 bytes
|
Rev | Line | |
---|
[d565449] | 1 | import { useState } from 'react';
|
---|
| 2 | import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';
|
---|
| 3 | function useObservable(observable$, initialValue) {
|
---|
| 4 | var _a = useState(initialValue), value = _a[0], update = _a[1];
|
---|
| 5 | useIsomorphicLayoutEffect(function () {
|
---|
| 6 | var s = observable$.subscribe(update);
|
---|
| 7 | return function () { return s.unsubscribe(); };
|
---|
| 8 | }, [observable$]);
|
---|
| 9 | return value;
|
---|
| 10 | }
|
---|
| 11 | export default useObservable;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.