@@ -38,7 +38,7 @@ error states, without assumptions about the shape of your data or the type of re
38
38
- Zero dependencies
39
39
- Works with promises, async/await and the Fetch API
40
40
- Choose between Render Props, Context-based helper components or the ` useAsync ` and ` useFetch ` hooks
41
- - Provides convenient ` isLoading ` , ` startedAt ` and ` finishedAt ` metadata
41
+ - Provides convenient ` isLoading ` , ` startedAt ` , ` finishedAt ` , et al metadata
42
42
- Provides ` cancel ` and ` reload ` actions
43
43
- Automatic re-run using ` watch ` or ` watchFn ` prop
44
44
- Accepts ` onResolve ` and ` onReject ` callbacks
@@ -201,7 +201,7 @@ is set to `"application/json"`.
201
201
202
202
### As a component
203
203
204
- The classic interface to React Async. Simply use <Async > directly in your JSX component tree, leveraging the render
204
+ The classic interface to React Async. Simply use ` <Async> ` directly in your JSX component tree, leveraging the render
205
205
props pattern:
206
206
207
207
``` js
@@ -248,14 +248,14 @@ const loadCustomer = ({ customerId }, { signal }) =>
248
248
const MyComponent = () => (
249
249
< Async promiseFn= {loadCustomer} customerId= {1 }>
250
250
< Async .Loading > Loading... < / Async .Loading >
251
- < Async .Resolved >
251
+ < Async .Fulfilled >
252
252
{data => (
253
253
< div>
254
254
< strong> Loaded some data: < / strong>
255
255
< pre> {JSON .stringify (data, null , 2 )}< / pre>
256
256
< / div>
257
257
)}
258
- < / Async .Resolved >
258
+ < / Async .Fulfilled >
259
259
< Async .Rejected > {error => ` Something went wrong: ${ error .message } ` }< / Async .Rejected >
260
260
< / Async>
261
261
)
@@ -279,7 +279,7 @@ const AsyncCustomer = createInstance({ promiseFn: loadCustomer }, "AsyncCustomer
279
279
280
280
const MyComponent = () => (
281
281
< AsyncCustomer customerId= {1 }>
282
- < AsyncCustomer .Resolved > {customer => ` Hello ${ customer .name } ` }< / AsyncCustomer .Resolved >
282
+ < AsyncCustomer .Fulfilled > {customer => ` Hello ${ customer .name } ` }< / AsyncCustomer .Fulfilled >
283
283
< / AsyncCustomer>
284
284
)
285
285
```
@@ -316,7 +316,7 @@ and listen to the new one. If `promise` is initially undefined, the React Async
316
316
317
317
#### ` promiseFn `
318
318
319
- > ` function(props: object , controller: AbortController): Promise `
319
+ > ` function(props: Object , controller: AbortController): Promise `
320
320
321
321
A function that returns a promise. It is automatically invoked in ` componentDidMount ` and ` componentDidUpdate ` .
322
322
The function receives all component props (or options) and an AbortController instance as arguments.
@@ -329,14 +329,14 @@ The function receives all component props (or options) and an AbortController in
329
329
330
330
#### ` deferFn `
331
331
332
- > ` function(args: any[], props: object , controller: AbortController): Promise `
332
+ > ` function(args: any[], props: Object , controller: AbortController): Promise `
333
333
334
334
A function that returns a promise. This is invoked only by manually calling ` run(...args) ` . Receives the same arguments
335
335
as ` promiseFn ` , as well as any arguments to ` run ` which are passed through as an array. The ` deferFn ` is commonly used
336
336
to send data to the server following a user action, such as submitting a form. You can use this in conjunction with
337
337
` promiseFn ` to fill the form with existing data, then updating it on submit with ` deferFn ` .
338
338
339
- > Be aware that when using both ` promiseFn ` and ` deferFn ` , the shape of their resolved value should match, because they
339
+ > Be aware that when using both ` promiseFn ` and ` deferFn ` , the shape of their fulfilled value should match, because they
340
340
> both update the same ` data ` .
341
341
342
342
#### ` watch `
@@ -348,7 +348,7 @@ reference check (`oldValue !== newValue`). If you need a more complex update che
348
348
349
349
#### ` watchFn `
350
350
351
- > ` function(props: object , prevProps: object ): boolean | any `
351
+ > ` function(props: Object , prevProps: Object ): boolean | any `
352
352
353
353
Re-runs the ` promiseFn ` when this callback returns truthy (called on every update). Any default props specified by
354
354
` createInstance ` are available too.
@@ -393,7 +393,7 @@ is set to `"application/json"`.
393
393
- ` error ` Rejected promise reason, cleared when new data arrives.
394
394
- ` initialValue ` The data or error that was provided through the ` initialValue ` prop.
395
395
- ` startedAt ` When the current/last promise was started.
396
- - ` finishedAt ` When the last promise was resolved or rejected.
396
+ - ` finishedAt ` When the last promise was fulfilled or rejected.
397
397
- ` status ` One of: ` initial ` , ` pending ` , ` fulfilled ` , ` rejected ` .
398
398
- ` isInitial ` true when no promise has ever started, or one started but was cancelled.
399
399
- ` isPending ` true when a promise is currently awaiting settlement. Alias: ` isLoading `
@@ -403,7 +403,7 @@ is set to `"application/json"`.
403
403
- ` counter ` The number of times a promise was started.
404
404
- ` cancel ` Cancel any pending promise.
405
405
- ` run ` Invokes the ` deferFn ` .
406
- - ` reload ` Re-runs the promise when invoked, using the any previous arguments.
406
+ - ` reload ` Re-runs the promise when invoked, using any previous arguments.
407
407
- ` setData ` Sets ` data ` to the passed value, unsets ` error ` and cancels any pending promise.
408
408
- ` setError ` Sets ` error ` to the passed value and cancels any pending promise.
409
409
@@ -454,15 +454,15 @@ These are available for import as `statusTypes`.
454
454
455
455
> ` boolean `
456
456
457
- ` true ` while a promise is pending (loading), ` false ` otherwise.
457
+ ` true ` while a promise is pending (aka loading), ` false ` otherwise.
458
458
459
459
Alias: ` isLoading `
460
460
461
461
#### ` isFulfilled `
462
462
463
463
> ` boolean `
464
464
465
- ` true ` when the last promise was fulfilled (resolved) with a value.
465
+ ` true ` when the last promise was fulfilled (aka resolved) with a value.
466
466
467
467
Alias: ` isResolved `
468
468
@@ -528,7 +528,7 @@ Renders only while the deferred promise is still waiting to be run, or you have
528
528
#### Props
529
529
530
530
- ` persist ` ` boolean ` Show until we have data, even while loading or when an error occurred. By default it hides as soon as the promise starts loading.
531
- - ` children ` ` function(state: object ): Node | Node ` Render function or React Node.
531
+ - ` children ` ` function(state: Object ): Node | Node ` Render function or React Node.
532
532
533
533
#### Examples
534
534
@@ -542,10 +542,10 @@ Renders only while the deferred promise is still waiting to be run, or you have
542
542
543
543
``` js
544
544
< Async .Initial persist>
545
- {({ error, isLoading , run }) => (
545
+ {({ error, isPending , run }) => (
546
546
< div>
547
- < p> This text is only rendered while the promise has not resolved yet.< / p>
548
- < button onClick= {run} disabled= {! isLoading }>
547
+ < p> This text is only rendered while the promise has not fulfilled yet.< / p>
548
+ < button onClick= {run} disabled= {! isPending }>
549
549
Run
550
550
< / button>
551
551
{error && < p> {error .message }< / p> }
@@ -556,14 +556,14 @@ Renders only while the deferred promise is still waiting to be run, or you have
556
556
557
557
### ` <Async.Pending> `
558
558
559
- This component renders only while the promise is loading (unsettled).
559
+ This component renders only while the promise is pending (aka loading) (unsettled).
560
560
561
561
Alias: ` <Async.Loading> `
562
562
563
563
#### Props
564
564
565
565
- ` initial ` ` boolean ` Show only on initial load (when ` data ` is ` undefined ` ).
566
- - ` children ` ` function(state: object ): Node | Node ` Render function or React Node.
566
+ - ` children ` ` function(state: Object ): Node | Node ` Render function or React Node.
567
567
568
568
#### Examples
569
569
@@ -586,7 +586,7 @@ Alias: `<Async.Resolved>`
586
586
#### Props
587
587
588
588
- ` persist ` ` boolean ` Show old data while loading new data. By default it hides as soon as a new promise starts.
589
- - ` children ` ` function(data: any, state: object ): Node | Node ` Render function or React Node.
589
+ - ` children ` ` function(data: any, state: Object ): Node | Node ` Render function or React Node.
590
590
591
591
#### Examples
592
592
@@ -595,7 +595,7 @@ Alias: `<Async.Resolved>`
595
595
```
596
596
597
597
``` js
598
- < Async .Fulfilled > {({ finishedAt }) => ` Last updated ${ startedAt .toISOString ()} ` }< / Async .Fulfilled >
598
+ < Async .Fulfilled > {(data , { finishedAt }) => ` Last updated ${ finishedAt .toISOString ()} ` }< / Async .Fulfilled >
599
599
```
600
600
601
601
### ` <Async.Rejected> `
@@ -605,7 +605,7 @@ This component renders only when the promise is rejected.
605
605
#### Props
606
606
607
607
- ` persist ` ` boolean ` Show old error while loading new data. By default it hides as soon as a new promise starts.
608
- - ` children ` ` function(error: Error, state: object ): Node | Node ` Render function or React Node.
608
+ - ` children ` ` function(error: Error, state: Object ): Node | Node ` Render function or React Node.
609
609
610
610
#### Examples
611
611
@@ -624,7 +624,7 @@ This component renders only when the promise is fulfilled or rejected.
624
624
#### Props
625
625
626
626
- ` persist ` ` boolean ` Show old data or error while loading new data. By default it hides as soon as a new promise starts.
627
- - ` children ` ` function(state: object ): Node | Node ` Render function or React Node.
627
+ - ` children ` ` function(state: Object ): Node | Node ` Render function or React Node.
628
628
629
629
## Usage examples
630
630
0 commit comments