9
9
<br />
10
10
11
11
<p align =" center " >
12
- <a href="https://github.com/ava/use-http/pulls">
13
- <img src="https://camo.githubusercontent.com/d4e0f63e9613ee474a7dfdc23c240b9795712c96/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e737667" />
14
- </a>
15
- <a href="https://circleci.com/gh/ava/use-http">
16
- <img src="https://img.shields.io/circleci/project/github/ava/use-http/master.svg" />
17
- </a>
18
- <a href="https://www.npmjs.com/package/use-http">
19
- <img src="https://img.shields.io/npm/dt/use-http.svg" />
20
- </a>
21
- <a href="https://lgtm.com/projects/g/ava/use-http/context:javascript">
22
- <img alt="undefined" src="https://img.shields.io/lgtm/grade/javascript/g/ava/use-http.svg?logo=lgtm&logoWidth=18"/>
23
- </a>
24
- <a href="http://packagequality.com/#?package=use-http">
25
- <img src="https://npm.packagequality.com/shield/use-http.svg" />
26
- </a>
27
- <a href="https://standardjs.com">
28
- <img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" />
29
- </a>
12
+ <a href =" https://github.com/ava/use-http/pulls " >
13
+ <img src="https://camo.githubusercontent.com/d4e0f63e9613ee474a7dfdc23c240b9795712c96/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e737667" />
14
+ </a >
15
+ <a href =" https://circleci.com/gh/ava/use-http " >
16
+ <img src="https://img.shields.io/circleci/project/github/ava/use-http/master.svg" />
17
+ </a >
18
+ <a href =" https://www.npmjs.com/package/use-http " >
19
+ <img src="https://img.shields.io/npm/dt/use-http.svg" />
20
+ </a >
21
+ <a href =" https://lgtm.com/projects/g/ava/use-http/context:javascript " >
22
+ <img alt="undefined" src="https://img.shields.io/lgtm/grade/javascript/g/ava/use-http.svg?logo=lgtm&logoWidth=18"/>
23
+ </a >
24
+ <a href =" http://packagequality.com/#?package=use-http " >
25
+ <img src="https://npm.packagequality.com/shield/use-http.svg" />
26
+ </a >
27
+ <a href =" https://standardjs.com " >
28
+ <img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" />
29
+ </a >
30
+ <a href =" https://www.youtube.com/channel/UCbQDX3YQJcQcISK_oyyYP6A " >
31
+ <img src="https://img.shields.io/badge/youtube-subscribe-RED.svg" />
32
+ </a >
30
33
31
34
<!-- [](https://spectrum.chat/next-js) -->
32
35
<!-- <a href="https://bundlephobia.com/result?p=use-http">
@@ -83,17 +86,20 @@ Features
83
86
Usage
84
87
-----
85
88
86
- ### Examples
87
- <ul >
88
- <li><a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-in-nextjs-nn9fm'>useFetch - Next.js</a></li>
89
- <li><a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/embed/km04k9k9x5'>useFetch - create-react-app</a></li>
90
- <li><a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-with-provider-c78w2'>useFetch + Provider</a></li>
91
- <li><a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-suspense-i22wv'>useFetch + Suspense</a></li>
92
- <li ><a target =" _blank " rel =" noopener noreferrer " href =' https://codesandbox.io/s/usefetch-provider-pagination-exttg ' >useFetch + Pagination + Provider</a ></li >
93
- <li><a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-provider-requestresponse-interceptors-s1lex'>useFetch + Request/Response Interceptors + Provider</a></li>
94
- <li><a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-retryon-retrydelay-s74q9'>useFetch + retryOn, retryDelay</a></li>
95
- <li><a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/graphql-usequery-provider-uhdmj'>useQuery - GraphQL</a></li>
96
- </ul >
89
+ ### Examples + Videos
90
+
91
+ - useFetch - managed state, request, response, etc. [ ![ ] ( https://img.shields.io/badge/example-blue.svg )] ( https://codesandbox.io/s/usefetch-request-response-managed-state-ruyi3?file=/src/index.js ) [ ![ ] ( https://img.shields.io/badge/video-red.svg )] ( https://www.youtube.com/watch?v=gtEwjpXbSik&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i )
92
+ - useFetch - route, path, Provider, etc. [ ![ ] ( https://img.shields.io/badge/example-blue.svg )] ( https://codesandbox.io/s/usefetch-with-provider-c78w2 ) [ ![ ] ( https://img.shields.io/badge/video-red.svg )] ( https://www.youtube.com/watch?v=33jqbLlQm3g&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i )
93
+ - useFetch - request/response interceptors [ ![ ] ( https://img.shields.io/badge/example-blue.svg )] ( https://codesandbox.io/s/usefetch-provider-requestresponse-interceptors-s1lex ) [ ![ ] ( https://img.shields.io/badge/video-red.svg )] ( https://www.youtube.com/watch?v=2xSQm_OYprc&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i )
94
+ - useFetch - retries, retryOn, retryDelay [ ![ ] ( https://img.shields.io/badge/example-blue.svg )] ( https://codesandbox.io/s/usefetch-retryon-retrydelay-s74q9 ) [ ![ ] ( https://img.shields.io/badge/video-red.svg )] ( https://www.youtube.com/watch?v=Y9zJwzR0vTg&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i )
95
+ - useFetch - abort, timeout, onAbort, onTimeout [ ![ ] ( https://img.shields.io/badge/video-red.svg )] ( https://www.youtube.com/watch?v=X9X9niivp-0&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i )
96
+ - useFetch - persist, cache [ ![ ] ( https://img.shields.io/badge/video-red.svg )] ( https://www.youtube.com/watch?v=EWd3ekEypM8&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i )
97
+ - useFetch - cacheLife, cachePolicy [ ![ ] ( https://img.shields.io/badge/video-red.svg )] ( https://www.youtube.com/watch?v=-8vq5VGMGnA&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i )
98
+ - useFetch - suspense <sup >(experimental)</sup > [ ![ ] ( https://img.shields.io/badge/example-blue.svg )] ( https://codesandbox.io/s/usefetch-suspense-i22wv ) [ ![ ] ( https://img.shields.io/badge/video-red.svg )] ( https://www.youtube.com/watch?v=MbWizFdJBoE&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i )
99
+ - useFetch - pagination [ ![ ] ( https://img.shields.io/badge/example-blue.svg )] ( https://codesandbox.io/s/usefetch-provider-pagination-exttg ) [ ![ ] ( https://img.shields.io/badge/video-red.svg )] ( https://www.youtube.com/watch?v=s-r6x1WrMns&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i&index=9 )
100
+ - useQuery - GraphQL [ ![ ] ( https://img.shields.io/badge/example-blue.svg )] ( https://codesandbox.io/s/graphql-usequery-provider-uhdmj )
101
+ - useFetch - Next.js [ ![ ] ( https://img.shields.io/badge/example-blue.svg )] ( https://codesandbox.io/s/usefetch-in-nextjs-nn9fm )
102
+ - useFetch - create-react-app [ ![ ] ( https://img.shields.io/badge/example-blue.svg )] ( https://codesandbox.io/embed/km04k9k9x5 )
97
103
98
104
<details open ><summary ><b >Basic Usage (managed state) <code >useFetch</code ></b ></summary >
99
105
@@ -136,6 +142,9 @@ function Todos() {
136
142
)
137
143
}
138
144
` ` `
145
+
146
+ <a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-request-response-managed-state-ruyi3?file=/src/index.js'><img width='150px' height='30px' src='https://codesandbox.io/static/img/play-codesandbox.svg' /></a> <a target="_blank" rel="noopener noreferrer" href='https://www.youtube.com/watch?v=gtEwjpXbSik&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i'><img width='150px' height='30px' src='https://github.com/ava/use-http/raw/master/public/watch-youtube-video.png' /></a>
147
+
139
148
</details>
140
149
141
150
<details><summary><b>Basic Usage (auto managed state) <code>useFetch</code></b></summary>
@@ -164,6 +173,10 @@ function Todos() {
164
173
)
165
174
}
166
175
` ` `
176
+
177
+ <!-- TODO: codesandbox + youtube -->
178
+ <!-- <a target="_blank" rel="noopener noreferrer" href='XXXXXX'><img width='150px' height='30px' src='https://github.com/ava/use-http/raw/master/public/watch-youtube-video.png' /></a> -->
179
+
167
180
</details>
168
181
169
182
@@ -196,7 +209,9 @@ const App = () => (
196
209
)
197
210
` ` `
198
211
199
- [](https://codesandbox.io/s/usefetch-with-provider-c78w2)
212
+ <!-- TODO: youtube -->
213
+ <a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-provider-requestresponse-interceptors-s1lex?file=/src/index.js'><img width='150px' height='30px' src='https://codesandbox.io/static/img/play-codesandbox.svg' /></a>
214
+ <!-- <a target="_blank" rel="noopener noreferrer" href='XXXXXXX'><img width='150px' height='30px' src='https://github.com/ava/use-http/raw/master/public/watch-youtube-video.png' /></a> -->
200
215
201
216
</details>
202
217
@@ -231,7 +246,7 @@ function App() {
231
246
}
232
247
` ` `
233
248
234
- []()
249
+ <a target="_blank" rel="noopener noreferrer" href=' https://codesandbox.io/s/usefetch-suspense-i22wv'><img width='150px' height='30px' src='https://codesandbox.io/ static/img/play-codesandbox.svg' /></a> <a target="_blank" rel="noopener noreferrer" href='https://www.youtube.com/watch?v=MbWizFdJBoE&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i'><img width='150px' height='30px' src='https://github.com/ava/use-http/raw/master/public/watch-youtube-video.png' /></a>
235
250
236
251
</details>
237
252
@@ -274,8 +289,6 @@ function App() {
274
289
}
275
290
` ` `
276
291
277
- []()
278
-
279
292
</details>
280
293
281
294
<div align="center">
@@ -340,13 +353,14 @@ const App = () => (
340
353
)
341
354
` ` `
342
355
343
- [](https://codesandbox.io/s/usefetch-provider-pagination-exttg)
356
+ <a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-provider-pagination-exttg?file=/src/index.js'><img width='150px' height='30px' src='https://codesandbox.io/static/img/play-codesandbox.svg' /></a> <a target="_blank" rel="noopener noreferrer" href='https://www.youtube.com/watch?v=s-r6x1WrMns&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i&index=9'><img width='150px' height='30px' src='https://github.com/ava/use-http/raw/master/public/watch-youtube-video.png' /></a>
357
+
344
358
345
359
</details>
346
360
347
361
<details open><summary><b>Destructured <code>useFetch</code></b></summary>
348
362
349
- ⚠️ Do not destructure the ` response` object! Technically you can do it, but if you need to access the ` response .ok ` from, for example, within a component's onClick handler, it will be a stale value for ` ok` where it will be correct for ` response .ok ` . ️️⚠️
363
+ ⚠️ Do not destructure the ` response` object! Details in [this video](https://youtu.be/gtEwjpXbSik?list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i&t=131). Technically you can do it, but if you need to access the ` response .ok ` from, for example, within a component's onClick handler, it will be a stale value for ` ok` where it will be correct for ` response .ok ` . ️️⚠️
350
364
351
365
` ` ` js
352
366
var [request, response, loading, error] = useFetch (' https://example.com' )
@@ -409,6 +423,8 @@ var {
409
423
} = request
410
424
` ` `
411
425
426
+ <a target="_blank" rel="noopener noreferrer" href='https://www.youtube.com/watch?v=gtEwjpXbSik&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i'><img width='150px' height='30px' src='https://github.com/ava/use-http/raw/master/public/watch-youtube-video.png' /></a>
427
+
412
428
</details>
413
429
414
430
@@ -424,8 +440,10 @@ request.post('/todos', {
424
440
no: ' way'
425
441
})
426
442
` ` `
427
- </details>
428
443
444
+ <a target="_blank" rel="noopener noreferrer" href='https://www.youtube.com/watch?v=33jqbLlQm3g&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i'><img width='150px' height='30px' src='https://github.com/ava/use-http/raw/master/public/watch-youtube-video.png' /></a>
445
+
446
+ </details>
429
447
430
448
<details><summary><b>Abort <code>useFetch</code></b></summary>
431
449
@@ -448,6 +466,9 @@ const searchGithubRepos = e => githubRepos.get(encodeURI(e.target.value))
448
466
))}
449
467
< / >
450
468
` ` `
469
+
470
+ <a target="_blank" rel="noopener noreferrer" href='https://www.youtube.com/watch?v=X9X9niivp-0&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i'><img width='150px' height='30px' src='https://github.com/ava/use-http/raw/master/public/watch-youtube-video.png' /></a>
471
+
451
472
</details>
452
473
453
474
@@ -544,7 +565,9 @@ export default function QueryComponent() {
544
565
)
545
566
}
546
567
```
547
- [](https://codesandbox.io/s/graphql-usequery-provider-uhdmj)
568
+
569
+ <a target="_blank" rel="noopener noreferrer" href=' https: // codesandbox.io/s/graphql-usequery-provider-uhdmj'><img width='150px' height='30px' src='https://codesandbox.io/static/img/play-codesandbox.svg' /></a>
570
+
548
571
549
572
##### Add a new todo
550
573
` ` ` jsx
@@ -649,7 +672,9 @@ function App() {
649
672
}
650
673
651
674
` ` `
652
- [](https://codesandbox.io/s/usefetch-provider-requestresponse-interceptors-s1lex)
675
+
676
+ <a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-provider-requestresponse-interceptors-s1lex'><img width='150px' height='30px' src='https://codesandbox.io/static/img/play-codesandbox.svg' /></a> <a target="_blank" rel="noopener noreferrer" href='https://www.youtube.com/watch?v=2xSQm_OYprc&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i'><img width='150px' height='30px' src='https://github.com/ava/use-http/raw/master/public/watch-youtube-video.png' /></a>
677
+
653
678
</details>
654
679
655
680
<details id='form-data'><summary><b>File Uploads (FormData)</b></summary>
@@ -709,7 +734,9 @@ const App = () => {
709
734
)
710
735
}
711
736
` ` `
712
- [](https://codesandbox.io/s/usefetch-different-response-types-c6csw)
737
+
738
+ <a target="_blank" rel="noopener noreferrer" href='https://codesandbox.io/s/usefetch-different-response-types-c6csw'><img width='150px' height='30px' src='https://codesandbox.io/static/img/play-codesandbox.svg' /></a>
739
+ <!-- <a target="_blank" rel="noopener noreferrer" href='XXXXXX'><img width='150px' height='30px' src='https://github.com/ava/use-http/raw/master/public/watch-youtube-video.png' /></a> -->
713
740
714
741
</details>
715
742
@@ -792,7 +819,7 @@ const TestRetry = () => {
792
819
}
793
820
` ` `
794
821
795
- []( https://codesandbox.io/s/usefetch-retryon-retrydelay-s74q9)
822
+ <a target="_blank" rel="noopener noreferrer" href=' https://codesandbox.io/s/usefetch-retryon-retrydelay-s74q9'><img width='150px' height='30px' src='https://codesandbox.io/ static/img/play-codesandbox.svg' /></a> <a target="_blank" rel="noopener noreferrer" href=' https://www.youtube.com/watch?v=Y9zJwzR0vTg&list=PLZIwrWkE9rCfYafpuEkF6swOtiqRX5r9i'><img width='150px' height='30px' src='https://github.com/ava/use-http/raw/master/public/watch-youtube-video.png' /></a>
796
823
797
824
</details>
798
825
@@ -1012,6 +1039,9 @@ Todos
1012
1039
// by attempting to extract it via these body interface
1013
1040
// methods, one by one in this order
1014
1041
responseType: [' json' , ' text' , ' blob' , ' formData' , ' arrayBuffer' ],
1042
+ // by default this is true, but if set to false
1043
+ // then we default to the responseType array of trying 'json' first, then 'text', etc.
1044
+ responseTypeGuessing: true ,
1015
1045
// ALSO, maybe there's a way to guess the proper `body interface method` for the correct response content-type.
1016
1046
// here's a stackoverflow with someone who's tried: https://bit.ly/2X8iaVG
1017
1047
0 commit comments