You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -855,6 +855,7 @@ This is exactly what you would pass to the normal js `fetch`, with a little extr
855
855
| `path` | When using a global `url` set in the `Provider`, this is useful for adding onto it | `''` |
856
856
| `persist` | Persists data for the duration of `cacheLife`. If `cacheLife` is not set it defaults to 24h. Currently only available in Browser. | `false` |
857
857
| `perPage` | Stops making more requests if there is no more data to fetch. (i.e. if we have 25 todos, and the perPage is 10, after fetching 2 times, we will have 20 todos. The last 5 tells us we don't have any more to fetch because it's less than 10) For pagination. | `0` |
858
+
| `responseType` | This will determine how the `data` field is set. If you put `json` then it will try to parse it as JSON. If you set it as an array, it will attempt to parse the `response` in the order of the types you put in the array. Read about why we don't put `formData` in the defaults [in the yellow Note part here](https://developer.mozilla.org/en-US/docs/Web/API/Body/formData). | `['json', 'text', 'blob', 'readableStream']` |
858
859
| `retries` | When a request fails or times out, retry the request this many times. By default it will not retry. | `0` |
859
860
| `retryDelay` | You can retry with certain intervals i.e. 30 seconds `30000` or with custom logic (i.e. to increase retry intervals). | `1000` |
860
861
| `retryOn` | You can retry on certain http status codes or have custom logic to decide whether to retry or not via a function. Make sure `retries >0` otherwise it won't retry. | `[]` |
@@ -911,6 +912,16 @@ const options = {
911
912
// Allows caching to persist after page refresh. Only supported in the Browser currently.
912
913
persist:false,
913
914
915
+
// this would basically call `await response.json()`
916
+
// and set the `data` and `response.data` field to the output
917
+
responseType:'json',
918
+
// OR can be an array. It's an array by default.
919
+
// We will try to get the `data` by attempting to extract
920
+
// it via these body interface methods, one by one in
921
+
// this order. We skip `formData` because it's mostly used
// amount of times it should retry before erroring out
915
926
retries:3,
916
927
@@ -1008,7 +1019,7 @@ Todos
1008
1019
- [ ] if calling `response.json()` and there is no response yet
1009
1020
- [ ] tests
1010
1021
- [ ] tests for SSR
1011
-
- [ ] tests for FormData (can also do it for react-native at same time. [see here](https://stackoverflow.com/questions/45842088/react-native-mocking-formdata-in-unit-tests))
1022
+
- [ ] tests for reactnative [see here](https://stackoverflow.com/questions/45842088/react-native-mocking-formdata-in-unit-tests)
1012
1023
- [ ] tests for GraphQL hooks `useMutation` + `useQuery`
1013
1024
- [ ] tests for stale `response` see this [PR](https://github.com/ava/use-http/pull/119/files)
1014
1025
- [ ] tests to make sure `response.formData()` and some of the other http `response methods` work properly
@@ -1034,12 +1045,6 @@ Todos
1034
1045
// to overwrite those of `useFetch` for
1035
1046
// `useMutation` and `useQuery`
1036
1047
},
1037
-
responseType:'json', // similar to axios
1038
-
// OR can be an array. We will try to get the `data`
1039
-
// by attempting to extract it via these body interface
1040
-
// methods, one by one in this order
1041
-
// we skip `formData` because it's mostly used for service workers
@@ -805,6 +805,7 @@ This is exactly what you would pass to the normal js `fetch`, with a little extr
805
805
| `onTimeout` | Called when the request times out. | empty function |
806
806
| `path` | When using a global `url` set in the `Provider`, this is useful for adding onto it | `''` |
807
807
| `persist` | Persists data for the duration of `cacheLife`. If `cacheLife` is not set it defaults to 24h. Currently only available in Browser. | `false` |
808
+
| `responseType` | This will determine how the `data` field is set. If you put `json` then it will try to parse it as JSON. If you set it as an array, it will attempt to parse the `response` in the order of the types you put in the array. Read about why we don't put `formData`in the defaults [in the yellow Note part here](https://developer.mozilla.org/en-US/docs/Web/API/Body/formData). | `['json', 'text', 'blob', 'readableStream']` |
808
809
|`perPage`| Stops making more requests if there is no more data to fetch. (i.e. if we have 25 todos, and the perPage is 10, after fetching 2 times, we will have 20todos. The last 5 tells us we don't have any more to fetch because it's less than 10) For pagination. |`0`|
809
810
|`retries`| When a request fails or times out, retry the request this many times. By default it will not retry. |`0`|
810
811
|`retryDelay`| You can retry with certain intervals i.e. 30 seconds `30000` or with custom logic (i.e. to increase retry intervals). |`1000`|
@@ -862,6 +863,16 @@ const options = {
862
863
// Allows caching to persist after page refresh. Only supported in the Browser currently.
863
864
persist:false,
864
865
866
+
// this would basically call `await response.json()`
867
+
// and set the `data` and `response.data` field to the output
868
+
responseType:'json',
869
+
// OR can be an array. It's an array by default.
870
+
// We will try to get the `data` by attempting to extract
871
+
// it via these body interface methods, one by one in
872
+
// this order. We skip `formData` because it's mostly used
invariant(isFunction(retryDelay)||Number.isInteger(retryDelayasnumber)&&retryDelay>=0,'`retryDelay` must be a positive number or a function returning a positive number.')
0 commit comments