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 77
77
<br />
78
78
- [ ** State** ] ( ./docs/State.md )
79
79
- [ ` createMemo ` ] ( ./docs/createMemo.md ) &mdash ; factory of memoized hooks.
80
+ - [ ` useCallbag ` ] ( ./docs/useCallbag.md ) &mdash ; tracks latest value of a callbag.
80
81
- [ ` useGetSet ` ] ( ./docs/useGetSet.md ) &mdash ; returns state getter ` get() ` instead of raw state.
81
82
- [ ` useGetSetState ` ] ( ./docs/useGetSetState.md ) &mdash ; as if [ ` useGetSet ` ] ( ./docs/useGetSet.md ) and [ ` useSetState ` ] ( ./docs/useSetState.md ) had a baby.
82
83
- [ ` 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`.
6
6
## Usage
7
7
8
8
``` jsx
9
+ import {useObservable } from ' react-use' ;
10
+
9
11
const counter$ = new BehaviorSubject (0 );
10
12
const Demo = () => {
11
13
const value = useObservable (counter$, 0 );
12
-
14
+
13
15
return (
14
16
< button onClick= {() => counter$ .next (value + 1 )}>
15
17
Clicked {value} times
Original file line number Diff line number Diff line change 36
36
"nano-css" : " ^3.4.0" ,
37
37
"rebound" : " ^0.1.0" ,
38
38
"ts-easing" : " ^0.1.0" ,
39
- "use-onclickoutside" : " ^0.1.0"
39
+ "use-onclickoutside" : " ^0.1.0" ,
40
+ "use-callbag" : " ^0.1.2"
40
41
},
41
42
"devDependencies" : {
42
43
"@storybook/react" : " ^3.4.11" ,
52
53
"@semantic-release/changelog" : " ^3.0.1" ,
53
54
"@semantic-release/npm" : " ^5.0.5" ,
54
55
"@semantic-release/git" : " ^7.0.5" ,
55
- "rxjs" : " ^6.3.3"
56
+ "rxjs" : " ^6.3.3" ,
57
+ "callbag-interval" : " ^1.1.0"
56
58
},
57
59
"peerDependencies" : {
58
60
"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';
3
3
import useAudio from './useAudio' ;
4
4
import useBattery from './useBattery' ;
5
5
import useBoolean from './useBoolean' ;
6
+ import useCallbag from './useCallbag' ;
6
7
import useCounter from './useCounter' ;
7
8
import useCss from './useCss' ;
8
9
import useFavicon from './useFavicon' ;
@@ -46,6 +47,7 @@ export {
46
47
useAudio ,
47
48
useBattery ,
48
49
useBoolean ,
50
+ useCallbag ,
49
51
useCounter ,
50
52
useCss ,
51
53
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:
2156
2156
resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b"
2157
2157
integrity sha1-JtII6onje1y95gJQoV8DHBak1ms=
2158
2158
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
+
2159
2176
camel-case@3.0.x :
2160
2177
version "3.0.0"
2161
2178
resolved "https://registry.yarnpkg.com/camel-case/-/camel-case-3.0.0.tgz#ca3c3688a4e9cf3a4cda777dc4dcbc713249cf73"
@@ -9512,6 +9529,13 @@ url@^0.11.0:
9512
9529
punycode "1.3.2"
9513
9530
querystring "0.2.0"
9514
9531
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
+
9515
9539
use-onclickoutside@^0.1.0 :
9516
9540
version "0.1.0"
9517
9541
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