File tree Expand file tree Collapse file tree 8 files changed +70
-3
lines changed Expand file tree Collapse file tree 8 files changed +70
-3
lines changed Original file line number Diff line number Diff line change 7777 <br />
7878- [ ** State** ] ( ./docs/State.md )
7979 - [ ` createMemo ` ] ( ./docs/createMemo.md ) &mdash ; factory of memoized hooks.
80+ - [ ` useCallbag ` ] ( ./docs/useCallbag.md ) &mdash ; tracks latest value of a callbag.
8081 - [ ` useGetSet ` ] ( ./docs/useGetSet.md ) &mdash ; returns state getter ` get() ` instead of raw state.
8182 - [ ` useGetSetState ` ] ( ./docs/useGetSetState.md ) &mdash ; as if [ ` useGetSet ` ] ( ./docs/useGetSet.md ) and [ ` useSetState ` ] ( ./docs/useSetState.md ) had a baby.
8283 - [ ` useObservable ` ] ( ./docs/useObservable.md ) &mdash ; tracks latest value of an ` Observable ` .
Original file line number Diff line number Diff line change 1+ # ` useCallbag `
2+
3+ React state hook that tracks the latest value of a callbag.
4+
5+
6+ ## Usage
7+
8+ ``` jsx
9+ import {useCallbag } from ' react-use' ;
10+ import interval from ' callbag-interval' ;
11+
12+ const Demo = () => {
13+ const count = useCallbag (() => interval (1000 ));
14+ return < span> {` Counter: ${ count} ` }< / span>
15+ };
16+ ```
Original file line number Diff line number Diff line change @@ -6,10 +6,12 @@ React state hook that tracks the latest value of an `Observable`.
66## Usage
77
88``` jsx
9+ import {useObservable } from ' react-use' ;
10+
911const counter$ = new BehaviorSubject (0 );
1012const Demo = () => {
1113 const value = useObservable (counter$, 0 );
12-
14+
1315 return (
1416 < button onClick= {() => counter$ .next (value + 1 )}>
1517 Clicked {value} times
Original file line number Diff line number Diff line change 3636 "nano-css" : " ^3.4.0" ,
3737 "rebound" : " ^0.1.0" ,
3838 "ts-easing" : " ^0.1.0" ,
39- "use-onclickoutside" : " ^0.1.0"
39+ "use-onclickoutside" : " ^0.1.0" ,
40+ "use-callbag" : " ^0.1.2"
4041 },
4142 "devDependencies" : {
4243 "@storybook/react" : " ^3.4.11" ,
5253 "@semantic-release/changelog" : " ^3.0.1" ,
5354 "@semantic-release/npm" : " ^5.0.5" ,
5455 "@semantic-release/git" : " ^7.0.5" ,
55- "rxjs" : " ^6.3.3"
56+ "rxjs" : " ^6.3.3" ,
57+ "callbag-interval" : " ^1.1.0"
5658 },
5759 "peerDependencies" : {
5860 "react" : " 16.7.0-alpha.0" ,
Original file line number Diff line number Diff line change 1+ import { useCallbag } from '..' ;
2+ import * as React from 'react' ;
3+ import { storiesOf } from '@storybook/react' ;
4+ import ShowDocs from '../util/ShowDocs' ;
5+ const interval = require ( 'callbag-interval' ) . default ;
6+
7+ const Demo = ( ) => {
8+ const count = useCallbag ( ( ) => ( interval as any ) ( 1000 ) ) ;
9+ return < span > { `Counter: ${ count } ` } </ span >
10+ } ;
11+
12+ storiesOf ( 'useCallbag' , module )
13+ . add ( 'Docs' , ( ) => < ShowDocs md = { require ( '../../docs/useCallbag.md' ) } /> )
14+ . add ( 'Demo' , ( ) =>
15+ < Demo />
16+ )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import useAsync from './useAsync';
33import useAudio from './useAudio' ;
44import useBattery from './useBattery' ;
55import useBoolean from './useBoolean' ;
6+ import useCallbag from './useCallbag' ;
67import useCounter from './useCounter' ;
78import useCss from './useCss' ;
89import useFavicon from './useFavicon' ;
@@ -46,6 +47,7 @@ export {
4647 useAudio ,
4748 useBattery ,
4849 useBoolean ,
50+ useCallbag ,
4951 useCounter ,
5052 useCss ,
5153 useFavicon ,
Original file line number Diff line number Diff line change 1+ import useCallbag from 'use-callbag'
2+
3+ export default useCallbag ;
4+
Original file line number Diff line number Diff line change @@ -2156,6 +2156,23 @@ call-me-maybe@^1.0.1:
21562156 resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b"
21572157 integrity sha1-JtII6onje1y95gJQoV8DHBak1ms=
21582158
2159+ callbag-interval@^1.1.0 :
2160+ version "1.1.0"
2161+ resolved "https://registry.yarnpkg.com/callbag-interval/-/callbag-interval-1.1.0.tgz#161ae4b5bf36b98bd5ef7caa3c3f8161fc032338"
2162+ integrity sha512-xkYj7t/l9+GaP0kvPi6LadF3ZNSiQAhbEzwnnTrDB/UtkBCrzKPZ9Kiti8P8oHYxL2jGEuRWi86PD3uM7qXLbg==
2163+ dependencies :
2164+ callbag "^1.1.0"
2165+
2166+ callbag-subscribe@^1.4.1 :
2167+ version "1.4.1"
2168+ resolved "https://registry.yarnpkg.com/callbag-subscribe/-/callbag-subscribe-1.4.1.tgz#f9bd86b713230c9113acf6b7c5c6baf7d5ec772f"
2169+ integrity sha512-FzvJK3ODP50UhZPhfCFwJZ+YP+Hg/6Fm1+d3m2UZacA1b+jSKARpyNTIpkWlf61rAHEgpwZF1head4URY+EEMw==
2170+
2171+ callbag@^1.1.0 :
2172+ version "1.1.0"
2173+ resolved "https://registry.yarnpkg.com/callbag/-/callbag-1.1.0.tgz#9cbbc3352832da43e764d588ed43121d4b09c42a"
2174+ integrity sha512-JVZp2vA53+THwOOan8eedGhS7xwzwR1u8HFK02WDMI9pITGoQ42j2sYP742qs7yddtEjIDGgNe1Y6DN90w3oIQ==
2175+
21592176camel-case@3.0.x :
21602177 version "3.0.0"
21612178 resolved "https://registry.yarnpkg.com/camel-case/-/camel-case-3.0.0.tgz#ca3c3688a4e9cf3a4cda777dc4dcbc713249cf73"
@@ -9512,6 +9529,13 @@ url@^0.11.0:
95129529 punycode "1.3.2"
95139530 querystring "0.2.0"
95149531
9532+ use-callbag@^0.1.2 :
9533+ version "0.1.2"
9534+ resolved "https://registry.yarnpkg.com/use-callbag/-/use-callbag-0.1.2.tgz#8f214952ccc488159b185ffe7ff17fccba7a73d3"
9535+ integrity sha512-8JJIpoqQaqJu9nfSTYe4WpJm2NyfHYgIDjouxhu4WOpgYI8W9IvMM32ecfcdZTzkWDuZkEyh3unGLMxA4wF7Bg==
9536+ dependencies :
9537+ callbag-subscribe "^1.4.1"
9538+
95159539use-onclickoutside@^0.1.0 :
95169540 version "0.1.0"
95179541 resolved "https://registry.yarnpkg.com/use-onclickoutside/-/use-onclickoutside-0.1.0.tgz#bc1998fe36728b22a4b9b28c95fbb468b3033e84"
You can’t perform that action at this time.
0 commit comments