File tree Expand file tree Collapse file tree 4 files changed +17
-5
lines changed Expand file tree Collapse file tree 4 files changed +17
-5
lines changed Original file line number Diff line number Diff line change 6
6
7
7
React hook for conveniently use Fetch API.
8
8
9
- * ** Tiny** (396 B). Calculated by [ size-limit] ( https://github.com/ai/size-limit )
9
+ * ** Tiny** (397 B). Calculated by [ size-limit] ( https://github.com/ai/size-limit )
10
10
* Both ** Flow** and ** TypeScript** types included
11
11
12
12
``` javascript
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " react-fetch-hook" ,
3
- "version" : " 1.6.4 " ,
3
+ "version" : " 1.7.0 " ,
4
4
"description" : " React fetch hook" ,
5
5
"scripts" : {
6
6
"flow" : " flow" ,
31
31
"ignore" : [
32
32
" react"
33
33
],
34
- "limit" : " 396 B" ,
34
+ "limit" : " 397 B" ,
35
35
"path" : " index.js"
36
36
},
37
37
{
Original file line number Diff line number Diff line change @@ -26,6 +26,18 @@ describe("useFetch", () => {
26
26
} ) ;
27
27
} ) ;
28
28
29
+ it ( "isLoading by default" , async ( ) => {
30
+ fetch . mockResponse ( JSON . stringify ( { data : "12345" } ) ) ;
31
+
32
+ const Component = ( ) => {
33
+ const result = useFetch ( "https://google.com" ) ;
34
+ return < div > { result . isLoading && "test" } </ div > ;
35
+ } ;
36
+
37
+ const { container, rerender } = render ( < Component /> ) ;
38
+ expect ( container ) . toHaveTextContent ( "test" ) ;
39
+ } ) ;
40
+
29
41
it ( "call with url and options" , async ( ) => {
30
42
fetch . mockResponse ( JSON . stringify ( { data : "12345" } ) ) ;
31
43
const options = {
Original file line number Diff line number Diff line change @@ -7,14 +7,14 @@ function usePromise (
7
7
) {
8
8
var inputs = Array . prototype . slice . call ( arguments , [ 1 ] )
9
9
var state = React . useState ( {
10
- isLoading : false
10
+ isLoading : ! ! callFunction
11
11
} )
12
12
13
13
React . useEffect ( function ( ) {
14
14
if ( ! callFunction ) {
15
15
return
16
16
}
17
- state [ 1 ] ( { data : state [ 0 ] . data , isLoading : true } )
17
+ ! state [ 0 ] . isLoading && state [ 1 ] ( { data : state [ 0 ] . data , isLoading : true } )
18
18
callFunction . apply ( null , inputs )
19
19
. then ( function ( data ) {
20
20
state [ 1 ] ( {
You can’t perform that action at this time.
0 commit comments