@@ -382,9 +382,14 @@ is set to `"application/json"`.
382382- ` data ` Last resolved promise value, maintained when new error arrives.
383383- ` error ` Rejected promise reason, cleared when new data arrives.
384384- ` initialValue ` The data or error that was provided through the ` initialValue ` prop.
385- - ` isLoading ` Whether or not a Promise is currently pending.
386385- ` startedAt ` When the current/last promise was started.
387386- ` finishedAt ` When the last promise was resolved or rejected.
387+ - ` status ` One of: ` initial ` , ` pending ` , ` fulfilled ` , ` rejected ` .
388+ - ` isInitial ` true when no promise has ever started, or one started but was cancelled.
389+ - ` isPending ` true when a promise is currently awaiting settlement. Alias: ` isLoading `
390+ - ` isFulfilled ` true when the last promise was fulfilled with a value. Alias: ` isResolved `
391+ - ` isRejected ` true when the last promise was rejected with a reason.
392+ - ` isSettled ` true when the last promise was fulfilled or rejected (not initial or pending).
388393- ` counter ` The number of times a promise was started.
389394- ` cancel ` Cancel any pending promise.
390395- ` run ` Invokes the ` deferFn ` .
@@ -410,12 +415,6 @@ Rejected promise reason, cleared when new data arrives.
410415
411416The data or error that was originally provided through the ` initialValue ` prop.
412417
413- #### ` isLoading `
414-
415- > ` boolean `
416-
417- ` true ` while a promise is pending, ` false ` otherwise.
418-
419418#### ` startedAt `
420419
421420> ` Date `
@@ -428,6 +427,47 @@ Tracks when the current/last promise was started.
428427
429428Tracks when the last promise was resolved or rejected.
430429
430+ #### ` status `
431+
432+ > ` string `
433+
434+ One of: ` initial ` , ` pending ` , ` fulfilled ` , ` rejected ` .
435+ These are available for import as ` statusTypes ` .
436+
437+ #### ` isInitial `
438+
439+ > ` boolean `
440+
441+ ` true ` while no promise has started yet, or one was started but cancelled.
442+
443+ #### ` isPending `
444+
445+ > ` boolean `
446+
447+ ` true ` while a promise is pending (loading), ` false ` otherwise.
448+
449+ Alias: ` isLoading `
450+
451+ #### ` isFulfilled `
452+
453+ > ` boolean `
454+
455+ ` true ` when the last promise was fulfilled (resolved) with a value.
456+
457+ Alias: ` isResolved `
458+
459+ #### ` isRejected `
460+
461+ > ` boolean `
462+
463+ ` true ` when the last promise was rejected with an error.
464+
465+ #### ` isSettled `
466+
467+ > ` boolean `
468+
469+ ` true ` when the last promise was either fulfilled or rejected (i.e. not initial or pending)
470+
431471#### ` counter `
432472
433473> ` number `
@@ -471,10 +511,45 @@ invoked after the state update is completed. Returns the error to enable chainin
471511React Async provides several helper components that make your JSX more declarative and less cluttered.
472512They don't have to be direct children of ` <Async> ` and you can use the same component several times.
473513
474- ### ` <Async.Loading> `
514+ ### ` <Async.Initial> `
515+
516+ Renders only while the deferred promise is still waiting to be run, or you have not provided any promise.
517+
518+ #### Props
519+
520+ - ` 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.
521+ - ` children ` ` function(state: object): Node | Node ` Render function or React Node.
522+
523+ #### Examples
524+
525+ ``` js
526+ < Async deferFn= {deferFn}>
527+ < Async .Initial >
528+ < p> This text is only rendered while ` run` has not yet been invoked on ` deferFn` .< / p>
529+ < / Async .Initial >
530+ < / Async>
531+ ```
532+
533+ ``` js
534+ < Async .Initial persist>
535+ {({ error, isLoading, run }) => (
536+ < div>
537+ < p> This text is only rendered while the promise has not resolved yet.< / p>
538+ < button onClick= {run} disabled= {! isLoading}>
539+ Run
540+ < / button>
541+ {error && < p> {error .message }< / p> }
542+ < / div>
543+ )}
544+ < / Async .Initial >
545+ ```
546+
547+ ### ` <Async.Pending> `
475548
476549This component renders only while the promise is loading (unsettled).
477550
551+ Alias: ` <Async.Loading> `
552+
478553#### Props
479554
480555- ` initial ` ` boolean ` Show only on initial load (when ` data ` is ` undefined ` ).
@@ -483,19 +558,21 @@ This component renders only while the promise is loading (unsettled).
483558#### Examples
484559
485560``` js
486- < Async .Loading initial>
561+ < Async .Pending initial>
487562 < p> This text is only rendered while performing the initial load.< / p>
488- < / Async .Loading >
563+ < / Async .Pending >
489564```
490565
491566``` js
492- < Async .Loading > {({ startedAt }) => ` Loading since ${ startedAt .toISOString ()} ` }< / Async .Loading >
567+ < Async .Pending > {({ startedAt }) => ` Loading since ${ startedAt .toISOString ()} ` }< / Async .Pending >
493568```
494569
495- ### ` <Async.Resolved > `
570+ ### ` <Async.Fulfilled > `
496571
497572This component renders only when the promise is fulfilled with data (` data !== undefined ` ).
498573
574+ Alias: ` <Async.Resolved> `
575+
499576#### Props
500577
501578- ` persist ` ` boolean ` Show old data while loading new data. By default it hides as soon as a new promise starts.
@@ -504,11 +581,11 @@ This component renders only when the promise is fulfilled with data (`data !== u
504581#### Examples
505582
506583``` js
507- < Async .Resolved persist> {data => < pre> {JSON .stringify (data)}< / pre> }< / Async .Resolved >
584+ < Async .Fulfilled persist> {data => < pre> {JSON .stringify (data)}< / pre> }< / Async .Fulfilled >
508585```
509586
510587``` js
511- < Async .Resolved > {({ finishedAt }) => ` Last updated ${ startedAt .toISOString ()} ` }< / Async .Resolved >
588+ < Async .Fulfilled > {({ finishedAt }) => ` Last updated ${ startedAt .toISOString ()} ` }< / Async .Fulfilled >
512589```
513590
514591### ` <Async.Rejected> `
@@ -530,39 +607,15 @@ This component renders only when the promise is rejected.
530607< Async .Rejected > {error => ` Unexpected error: ${ error .message } ` }< / Async .Rejected >
531608```
532609
533- ### ` <Async.Pending > `
610+ ### ` <Async.Settled > `
534611
535- Renders only while the deferred promise is still pending (not yet run), or you have not provided any promise .
612+ This component renders only when the promise is fulfilled or rejected .
536613
537614#### Props
538615
539- - ` 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 .
616+ - ` persist ` ` boolean ` Show old data or error while loading new data . By default it hides as soon as a new promise starts.
540617- ` children ` ` function(state: object): Node | Node ` Render function or React Node.
541618
542- #### Examples
543-
544- ``` js
545- < Async deferFn= {deferFn}>
546- < Async .Pending >
547- < p> This text is only rendered while ` run` has not yet been invoked on ` deferFn` .< / p>
548- < / Async .Pending >
549- < / Async>
550- ```
551-
552- ``` js
553- < Async .Pending persist>
554- {({ error, isLoading, run }) => (
555- < div>
556- < p> This text is only rendered while the promise has not resolved yet.< / p>
557- < button onClick= {run} disabled= {! isLoading}>
558- Run
559- < / button>
560- {error && < p> {error .message }< / p> }
561- < / div>
562- )}
563- < / Async .Pending >
564- ```
565-
566619## Usage examples
567620
568621Here's several examples to give you an idea of what's possible with React Async. For fully working examples, please
0 commit comments