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
The library provides a hook `useHttpRequest` managing the state of the http request. Such state is returned by the hook along with a function to trigger the request. See [params](#http-request-hook-params) and [return](#http-request-hook-return) for more info. A dedicated hook is provided for every http method: `useHttpGet`, `useHttpPost`, `useHttpPatch`, `useHttpPut`, `useHttpDelete`.
289
+
290
+
### Http request hook params
291
+
| Parameter | Type | Description |
292
+
| --------- | ---- | ----------- |
293
+
| baseUrlOverride | string | The base url of the request. If provided, it would override the [provider](#provider) base url.
294
+
| relativeUrl | string | The url relative to the base one (e.g. posts/1).
295
+
| parser |[HttpResponseParser](src/client/types.ts)| An optional response parser that would override the [provider](#provider) global one. |
296
+
| requestOptions |[HttpRequestOptions](./src/client/types.ts)| The options carried by the fetch request. |
297
+
| initialData | any | The value that the state assumes initially before the request is send. |
298
+
| fetchOnBootstrap | boolean | Tell if the fetch must be triggered automatically when mounting the component or not. In the second case we would like to have a manual fetch, this is optained by a request function returned by the hook. |
299
+
300
+
### Http request hook return
301
+
Returns an array of two elements, the first one embeds the state of the http request and the second one is a function that can be used to trigger the http request. The table below describes the shape (i.e. properties) of http request state.
302
+
303
+
### Http request state
304
+
| Property | Type | Description |
305
+
| --------- | ---- | ----------- |
306
+
| pristine | boolean | Tells if the request has been dispatched. |
307
+
| errored | boolean | Tells if the request has returned an error. |
308
+
| isLoading | boolean | Tells if the request is pending. |
309
+
| error | unknown | property evaluated by the error generated by the backend api. |
310
+
| data | any | The response provided by the backend api. |
311
+
312
+
### Example – Http request hook triggered automatically on component mount
0 commit comments