@@ -267,7 +267,7 @@ by passing in the state, or with `<Async>` by using Context. Each of these compo
267
267
rendering of its children based on the current state.
268
268
269
269
``` jsx
270
- import { useAsync , Pending , Fulfilled , Rejected } from " react-async"
270
+ import { useAsync , IfPending , IfFulfilled , IfRejected } from " react-async"
271
271
272
272
const loadCustomer = async ({ customerId }, { signal }) => {
273
273
// ...
@@ -277,16 +277,16 @@ const MyComponent = () => {
277
277
const state = useAsync ({ promiseFn: loadCustomer, customerId: 1 })
278
278
return (
279
279
<>
280
- < Pending state= {state}> Loading... < / Pending >
281
- < Rejected state= {state}> {error => ` Something went wrong: ${ error .message } ` }< / Rejected >
282
- < Fulfilled state= {state}>
280
+ < IfPending state= {state}> Loading... < / IfPending >
281
+ < IfRejected state= {state}> {error => ` Something went wrong: ${ error .message } ` }< / IfRejected >
282
+ < IfFulfilled state= {state}>
283
283
{data => (
284
284
< div>
285
285
< strong> Loaded some data: < / strong>
286
286
< pre> {JSON .stringify (data, null , 2 )}< / pre>
287
287
< / div>
288
288
)}
289
- < / Fulfilled >
289
+ < / IfFulfilled >
290
290
< / >
291
291
)
292
292
}
@@ -607,7 +607,7 @@ invoked after the state update is completed. Returns the error to enable chainin
607
607
React Async provides several helper components that make your JSX more declarative and less cluttered.
608
608
They don't have to be direct children of ` <Async> ` and you can use the same component several times.
609
609
610
- ### ` <Initial > ` / ` <Async.Initial> `
610
+ ### ` <IfInitial > ` / ` <Async.Initial> `
611
611
612
612
Renders only while the deferred promise is still waiting to be run, or you have not provided any promise.
613
613
@@ -622,9 +622,9 @@ Renders only while the deferred promise is still waiting to be run, or you have
622
622
``` jsx
623
623
const state = useAsync (... )
624
624
return (
625
- < Initial state= {state}>
625
+ < IfInitial state= {state}>
626
626
< p> This text is only rendered while ` run` has not yet been invoked on ` deferFn` .< / p>
627
- < / Initial >
627
+ < / IfInitial >
628
628
)
629
629
```
630
630
@@ -650,7 +650,7 @@ return (
650
650
< / Async .Initial >
651
651
```
652
652
653
- ### ` <Pending > ` / ` <Async.Pending> `
653
+ ### ` <IfPending > ` / ` <Async.Pending> `
654
654
655
655
This component renders only while the promise is pending (loading / unsettled).
656
656
@@ -667,9 +667,9 @@ Alias: `<Async.Loading>`
667
667
``` jsx
668
668
const state = useAsync (... )
669
669
return (
670
- < Pending state= {state}>
670
+ < IfPending state= {state}>
671
671
< p> This text is only rendered while performing the initial load.< / p>
672
- < / Pending >
672
+ < / IfPending >
673
673
)
674
674
```
675
675
@@ -683,7 +683,7 @@ return (
683
683
< Async .Pending > {({ startedAt }) => ` Loading since ${ startedAt .toISOString ()} ` }< / Async .Pending >
684
684
```
685
685
686
- ### ` <Fulfilled > ` / ` <Async.Fulfilled> `
686
+ ### ` <IfFulfilled > ` / ` <Async.Fulfilled> `
687
687
688
688
This component renders only when the promise is fulfilled (resolved to a value, could be ` undefined ` ).
689
689
@@ -700,9 +700,9 @@ Alias: `<Async.Resolved>`
700
700
``` jsx
701
701
const state = useAsync (... )
702
702
return (
703
- < Fulfilled state= {state}>
703
+ < IfFulfilled state= {state}>
704
704
{data => < pre> {JSON .stringify (data)}< / pre> }
705
- < / Fulfilled >
705
+ < / IfFulfilled >
706
706
)
707
707
```
708
708
@@ -716,7 +716,7 @@ return (
716
716
< / Async .Fulfilled >
717
717
```
718
718
719
- ### ` <Rejected > ` / ` <Async.Rejected> `
719
+ ### ` <IfRejected > ` / ` <Async.Rejected> `
720
720
721
721
This component renders only when the promise is rejected.
722
722
@@ -730,7 +730,7 @@ This component renders only when the promise is rejected.
730
730
731
731
``` jsx
732
732
const state = useAsync (... )
733
- return < Rejected state= {state}> Oops.< / Rejected >
733
+ return < IfRejected state= {state}> Oops.< / IfRejected >
734
734
```
735
735
736
736
``` jsx
@@ -741,7 +741,7 @@ return <Rejected state={state}>Oops.</Rejected>
741
741
< Async .Rejected > {error => ` Unexpected error: ${ error .message } ` }< / Async .Rejected >
742
742
```
743
743
744
- ### ` <Settled > ` / ` <Async.Settled> `
744
+ ### ` <IfSettled > ` / ` <Async.Settled> `
745
745
746
746
This component renders only when the promise is fulfilled or rejected.
747
747
@@ -755,7 +755,7 @@ This component renders only when the promise is fulfilled or rejected.
755
755
756
756
``` jsx
757
757
const state = useAsync (... )
758
- return < Settled state= {state}> {state => ` Finished at ${ state .finishedAt .toISOString ()} ` < / Settled >
758
+ return < IfSettled state= {state}> {state => ` Finished at ${ state .finishedAt .toISOString ()} ` < / IfSettled >
759
759
` ` `
760
760
761
761
## Usage examples
0 commit comments