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 66
77React hook for conveniently use Fetch API.
88
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 )
1010* Both ** Flow** and ** TypeScript** types included
1111
1212``` javascript
Original file line number Diff line number Diff line change 11{
22 "name" : " react-fetch-hook" ,
3- "version" : " 1.6.4 " ,
3+ "version" : " 1.7.0 " ,
44 "description" : " React fetch hook" ,
55 "scripts" : {
66 "flow" : " flow" ,
3131 "ignore" : [
3232 " react"
3333 ],
34- "limit" : " 396 B" ,
34+ "limit" : " 397 B" ,
3535 "path" : " index.js"
3636 },
3737 {
Original file line number Diff line number Diff line change @@ -26,6 +26,18 @@ describe("useFetch", () => {
2626 } ) ;
2727 } ) ;
2828
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+
2941 it ( "call with url and options" , async ( ) => {
3042 fetch . mockResponse ( JSON . stringify ( { data : "12345" } ) ) ;
3143 const options = {
Original file line number Diff line number Diff line change @@ -7,14 +7,14 @@ function usePromise (
77) {
88 var inputs = Array . prototype . slice . call ( arguments , [ 1 ] )
99 var state = React . useState ( {
10- isLoading : false
10+ isLoading : ! ! callFunction
1111 } )
1212
1313 React . useEffect ( function ( ) {
1414 if ( ! callFunction ) {
1515 return
1616 }
17- state [ 1 ] ( { data : state [ 0 ] . data , isLoading : true } )
17+ ! state [ 0 ] . isLoading && state [ 1 ] ( { data : state [ 0 ] . data , isLoading : true } )
1818 callFunction . apply ( null , inputs )
1919 . then ( function ( data ) {
2020 state [ 1 ] ( {
You can’t perform that action at this time.
0 commit comments