@@ -46,28 +46,28 @@ yarn add react-request
4646
4747### Documentation
4848
49- * [ Getting Started] ( #getting-started )
50- * [ API] ( #api )
51- * [ \< Fetch/\> ] ( #fetch- )
52- * [ fetchDedupe()] ( #fetchdedupe-input--init--dedupeoptions- )
53- * [ getRequestKey()] ( #getrequestkey-url-method-body-responsetype- )
54- * [ isRequestInFlight()] ( #isrequestinflight-requestkey- )
55- * [ clearRequestCache()] ( #clearrequestcache )
56- * [ clearResponseCache()] ( #clearresponsecache )
57- * [ Guides ⇗] ( ./docs/guides/INDEX.md )
58- * [ Response Caching ⇗] ( ./docs/guides/response-caching.md )
59- * [ Request Deduplication ⇗] ( ./docs/guides/request-deduplication.md )
60- * [ Request Keys ⇗] ( ./docs/guides/request-keys.md )
61- * [ Best Practices ⇗] ( ./docs/guides/best-practices.md )
62- * [ Using the ` lazy ` Prop ⇗] ( ./docs/guides/using-the-lazy-prop.md )
63- * [ Aborting ⇗] ( ./docs/guides/aborting.md )
64- * [ Differences with ` fetch() ` ⇗] ( ./docs/guides/differences-with-fetch.md )
65- * [ Differences with React Apollo ⇗] ( ./docs/guides/differences-with-apollo.md )
66- * [ Integration with Other Technologies ⇗] ( ./docs/guides/integration-with-other-technologies.md )
67- * [ Examples ⇗] ( ./docs/examples.md )
68- * [ FAQ ⇗] ( ./docs/FAQ.md )
69- * [ Roadmap ⇗] ( ./ROADMAP.md )
70- * [ Acknowledgements] ( #acknowledgements )
49+ - [ Getting Started] ( #getting-started )
50+ - [ API] ( #api )
51+ - [ \< Fetch/\> ] ( #fetch- )
52+ - [ fetchDedupe()] ( #fetchdedupe-input--init--dedupeoptions- )
53+ - [ getRequestKey()] ( #getrequestkey-url-method-body-responsetype- )
54+ - [ isRequestInFlight()] ( #isrequestinflight-requestkey- )
55+ - [ clearRequestCache()] ( #clearrequestcache )
56+ - [ clearResponseCache()] ( #clearresponsecache )
57+ - [ Guides ⇗] ( ./docs/guides/INDEX.md )
58+ - [ Response Caching ⇗] ( ./docs/guides/response-caching.md )
59+ - [ Request Deduplication ⇗] ( ./docs/guides/request-deduplication.md )
60+ - [ Request Keys ⇗] ( ./docs/guides/request-keys.md )
61+ - [ Best Practices ⇗] ( ./docs/guides/best-practices.md )
62+ - [ Using the ` lazy ` Prop ⇗] ( ./docs/guides/using-the-lazy-prop.md )
63+ - [ Aborting ⇗] ( ./docs/guides/aborting.md )
64+ - [ Differences with ` fetch() ` ⇗] ( ./docs/guides/differences-with-fetch.md )
65+ - [ Differences with React Apollo ⇗] ( ./docs/guides/differences-with-apollo.md )
66+ - [ Integration with Other Technologies ⇗] ( ./docs/guides/integration-with-other-technologies.md )
67+ - [ Examples ⇗] ( ./docs/examples.md )
68+ - [ FAQ ⇗] ( ./docs/FAQ.md )
69+ - [ Roadmap ⇗] ( ./ROADMAP.md )
70+ - [ Acknowledgements] ( #acknowledgements )
7171
7272### Getting Started
7373
@@ -124,7 +124,7 @@ class App extends Component {
124124 < Fetch
125125 url= " https://jsonplaceholder.typicode.com/posts/1"
126126 method= " DELETE"
127- / >
127+ / > ,
128128 ]}>
129129 {([readPost , deletePost ]) => {
130130 return (
@@ -159,19 +159,19 @@ API as a prop, in addition to a few other things.
159159
160160The props that come from the ` fetch() ` method are:
161161
162- * ` url `
163- * ` method ` : defaults to ` "GET" `
164- * ` body `
165- * ` credentials `
166- * ` headers `
167- * ` mode `
168- * ` cache `
169- * ` redirect `
170- * ` referrer ` : defaults to ` "about:client" `
171- * ` referrerPolicy ` : defaults to ` "" `
172- * ` integrity ` : defaults to ` "" `
173- * ` keepalive `
174- * ` signal `
162+ - ` url `
163+ - ` method ` : defaults to ` "GET" `
164+ - ` body `
165+ - ` credentials `
166+ - ` headers `
167+ - ` mode `
168+ - ` cache `
169+ - ` redirect `
170+ - ` referrer ` : defaults to ` "about:client" `
171+ - ` referrerPolicy ` : defaults to ` "" `
172+ - ` integrity ` : defaults to ` "" `
173+ - ` keepalive `
174+ - ` signal `
175175
176176To learn more about the valid options for these props, refer to the
177177[ ` fetch() ` ] ( https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch )
@@ -185,7 +185,7 @@ The following example demonstrates some of the most commonly-used props that com
185185 method= " patch"
186186 credentials= " same-origin"
187187 headers= {{
188- ' csrf-token' : myCsrfToken
188+ ' csrf-token' : myCsrfToken,
189189 }}
190190 body= {JSON .stringify ({ title: ' New post' })}>
191191 {({ doFetch }) => {
@@ -201,34 +201,37 @@ In addition to the `fetch()` props, there are a number of other useful props.
201201The [ render prop] ( https://cdb.reacttraining.com/use-a-render-prop-50de598f11ce ) of this component.
202202It is called with one argument, ` result ` , an object with the following keys:
203203
204- * ` fetching ` : A Boolean representing whether or not a request is currently in flight for this component
205- * ` failed ` : A Boolean representing whether or not the request failed for any reason. This includes network
204+ - ` fetching ` : A Boolean representing whether or not a request is currently in flight for this component
205+ - ` failed ` : A Boolean representing whether or not the request failed for any reason. This includes network
206206 errors and status codes that are greater than or equal to` 400 ` .
207- * ` error ` : An error object representing a network error occurred. Note that HTTP "error" status codes do not
207+ - ` error ` : An error object representing a network error occurred. Note that HTTP "error" status codes do not
208208 cause errors; only failed or aborted network requests do. For more, see the
209209 [ "Using Fetch" MDN guide] ( https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful ) .
210- * ` response ` : An instance of [ Response] ( https://developer.mozilla.org/en-US/docs/Web/API/Response ) . The
210+ - ` response ` : An instance of [ Response] ( https://developer.mozilla.org/en-US/docs/Web/API/Response ) . The
211211 [ ` body ` ] ( https://developer.mozilla.org/en-US/docs/Web/API/Body ) will already be read, and made
212212 available to you as ` response.data ` .
213- * ` data ` : The data returned in ` response ` . This will be different from ` response.data ` if a
213+ - ` data ` : The data returned in ` response ` . This will be different from ` response.data ` if a
214214 ` transformData ` prop was passed to ` <Fetch/> ` .
215- * ` doFetch ` : A function that makes the HTTP request. See notes below.
216- * ` url ` : The URL that was passed into ` <Fetch /> ` .
217- * ` requestName ` : The name of the request (see ` requestName ` below)
218- * ` requestKey ` : The computed [ request key] ( ./docs/guides/request-keys.md )
215+ - ` doFetch ` : A function that makes the HTTP request. See notes below.
216+ - ` url ` : The URL that was passed into ` <Fetch /> ` .
217+ - ` requestName ` : The name of the request (see ` requestName ` below)
218+ - ` requestKey ` : The computed [ request key] ( ./docs/guides/request-keys.md )
219219
220220There are three common use cases for the ` doFetch ` prop:
221221
222- * You can use it to "refresh" the data by making a follow-up request for read requests
223- * You can use it to retry the request if there is any sort of error
224- * You must manually call this method to actually make the request anytime that the ` lazy ` prop
222+ - You can use it to "refresh" the data by making a follow-up request for read requests
223+ - You can use it to retry the request if there is any sort of error
224+ - You must manually call this method to actually make the request anytime that the ` lazy ` prop
225225 is passed as ` true ` .
226226
227227` doFetch ` accepts one argument: ` options ` . Any of the ` fetch() ` options, such as ` url ` , ` method ` , and
228228` body ` are valid ` options ` . You may also specify a new ` requestKey ` if you are manually generating your
229229own keys. This method allows you to customize the request from within the component based on the
230230component's state.
231231
232+ ` doFetch ` returns a Promise that ** always** resolves. It resolves to the same argument that the
233+ [ ` afterFetch ` ] ( #afterFetch ) prop receives.
234+
232235##### ` lazy `
233236
234237Whether or not the request will be called when the component mounts. The default value
@@ -252,10 +255,10 @@ is based on the request method that you use.
252255A function that is called just before a network request is initiated. It is called
253256with one argument, an object with the following keys:
254257
255- * ` url ` : The URL of the request
256- * ` init ` : The second argument passed to ` global.fetch() ` , which specifies things
258+ - ` url ` : The URL of the request
259+ - ` init ` : The second argument passed to ` global.fetch() ` , which specifies things
257260 such as the body, method, and so on
258- * ` requestKey ` : Either the computed request key, or the value of the
261+ - ` requestKey ` : Either the computed request key, or the value of the
259262 ` requestKey ` prop
260263
261264This feature is useful for analytics, or syncing response data with a data store such
@@ -268,16 +271,16 @@ as [Redux](https://github.com/reactjs/redux/).
268271A function that is called anytime that a network response is received. It is called
269272with one argument, an object with the following keys:
270273
271- * ` url ` : The URL of the request
272- * ` init ` : The second argument passed to ` global.fetch() ` , which specifies things
274+ - ` url ` : The URL of the request
275+ - ` init ` : The second argument passed to ` global.fetch() ` , which specifies things
273276 such as the body, method, and so on
274- * ` requestKey ` : Either the computed request key, or the value of the
277+ - ` requestKey ` : Either the computed request key, or the value of the
275278 ` requestKey ` prop
276- * ` response ` : The response that was received from the HTTP request
277- * ` data ` : The transformed data from the response. This will be different from
279+ - ` response ` : The response that was received from the HTTP request
280+ - ` data ` : The transformed data from the response. This will be different from
278281 ` response.data ` if a ` transformData ` function was passed as a prop to ` <Fetch/> ` .
279- * ` error ` : An error returned from the HTTP request
280- * ` didUnmount ` : A Boolean representing whether or not the component has unmounted
282+ - ` error ` : An error returned from the HTTP request
283+ - ` didUnmount ` : A Boolean representing whether or not the component has unmounted
281284
282285This can be used for analytics or syncing response data with a data store such
283286as [ Redux] ( https://github.com/reactjs/redux/ ) .
@@ -351,7 +354,7 @@ about the response, such as its status code.
351354 responseType= " text"
352355 transformData= {countryName => {
353356 return {
354- countryName
357+ countryName,
355358 };
356359 }}>
357360 {({ data }) => {
@@ -383,10 +386,10 @@ everywhere, we tend to give them names to help humans read and debug the code.
383386
384387This determines how the request interacts with the cache. Valid options are:
385388
386- * ` " cache-first" `
387- * ` " cache-and-network" `
388- * ` " network-only" `
389- * ` " cache-only" `
389+ - ` " cache-first" `
390+ - ` " cache-and-network" `
391+ - ` " network-only" `
392+ - ` " cache-only" `
390393
391394For documentation on what each of these values do, refer to the [response caching guide](./docs/guides/response-caching.md).
392395
0 commit comments