@@ -50,9 +50,10 @@ error states, without assumptions about the shape of your data or the type of re
5050
5151[ abortable fetch ] : https://developers.google.com/web/updates/2017/09/abortable-fetch
5252
53- > ## Upgrading to v6
53+ > ## Upgrading to v8
5454>
55- > Version 6 comes with a breaking change. See [ Upgrading] ( #upgrading ) for details.
55+ > Version 8 comes with breaking changes. See [ Upgrading] ( #upgrading ) for details.
56+ > A [ codemod] ( https://github.com/ghengeveld/react-async/tree/master/codemods ) is available.
5657
5758# Table of Contents
5859
@@ -121,11 +122,26 @@ yarn add react-async
121122
122123### Upgrading
123124
125+ #### Upgrade to v8
126+
127+ All standalone helper components were renamed to avoid import naming collision.
128+
129+ - ` <Initial> ` was renamed to ` <IfInitial> ` .
130+ - ` <Pending> ` was renamed to ` <IfPending> ` .
131+ - ` <Fulfilled> ` was renamed to ` <IfFulfilled> ` .
132+ - ` <Rejected> ` was renamed to ` <IfRejected ` .
133+ - ` <Settled> ` was renamed to ` <IfSettled> ` .
134+
135+ > A [ codemod] ( https://github.com/ghengeveld/react-async/tree/master/codemods ) is available to automate the upgrade.
136+
124137#### Upgrade to v6
125138
126139- ` <Async.Pending> ` was renamed to ` <Async.Initial> ` .
140+ - Some of the other helpers were also renamed, but the old ones remain as alias.
127141- Don't forget to deal with any custom instances of ` <Async> ` when upgrading.
128142
143+ > A [ codemod] ( https://github.com/ghengeveld/react-async/tree/master/codemods ) is available to automate the upgrade.
144+
129145#### Upgrade to v4
130146
131147- ` deferFn ` now receives an ` args ` array as the first argument, instead of arguments to ` run ` being spread at the front
@@ -267,7 +283,7 @@ by passing in the state, or with `<Async>` by using Context. Each of these compo
267283rendering of its children based on the current state.
268284
269285``` jsx
270- import { useAsync , Pending , Fulfilled , Rejected } from " react-async"
286+ import { useAsync , IfPending , IfFulfilled , IfRejected } from " react-async"
271287
272288const loadCustomer = async ({ customerId }, { signal }) => {
273289 // ...
@@ -277,16 +293,16 @@ const MyComponent = () => {
277293 const state = useAsync ({ promiseFn: loadCustomer, customerId: 1 })
278294 return (
279295 <>
280- < Pending state= {state}> Loading... < / Pending >
281- < Rejected state= {state}> {error => ` Something went wrong: ${ error .message } ` }< / Rejected >
282- < Fulfilled state= {state}>
296+ < IfPending state= {state}> Loading... < / IfPending >
297+ < IfRejected state= {state}> {error => ` Something went wrong: ${ error .message } ` }< / IfRejected >
298+ < IfFulfilled state= {state}>
283299 {data => (
284300 < div>
285301 < strong> Loaded some data: < / strong>
286302 < pre> {JSON .stringify (data, null , 2 )}< / pre>
287303 < / div>
288304 )}
289- < / Fulfilled >
305+ < / IfFulfilled >
290306 < / >
291307 )
292308}
@@ -607,7 +623,7 @@ invoked after the state update is completed. Returns the error to enable chainin
607623React Async provides several helper components that make your JSX more declarative and less cluttered.
608624They don't have to be direct children of ` <Async> ` and you can use the same component several times.
609625
610- ### ` <Initial > ` / ` <Async.Initial> `
626+ ### ` <IfInitial > ` / ` <Async.Initial> `
611627
612628Renders only while the deferred promise is still waiting to be run, or you have not provided any promise.
613629
@@ -622,9 +638,9 @@ Renders only while the deferred promise is still waiting to be run, or you have
622638``` jsx
623639const state = useAsync (... )
624640return (
625- < Initial state= {state}>
641+ < IfInitial state= {state}>
626642 < p> This text is only rendered while ` run` has not yet been invoked on ` deferFn` .< / p>
627- < / Initial >
643+ < / IfInitial >
628644)
629645```
630646
@@ -650,7 +666,7 @@ return (
650666< / Async .Initial >
651667```
652668
653- ### ` <Pending > ` / ` <Async.Pending> `
669+ ### ` <IfPending > ` / ` <Async.Pending> `
654670
655671This component renders only while the promise is pending (loading / unsettled).
656672
@@ -667,9 +683,9 @@ Alias: `<Async.Loading>`
667683``` jsx
668684const state = useAsync (... )
669685return (
670- < Pending state= {state}>
686+ < IfPending state= {state}>
671687 < p> This text is only rendered while performing the initial load.< / p>
672- < / Pending >
688+ < / IfPending >
673689)
674690```
675691
@@ -683,7 +699,7 @@ return (
683699< Async .Pending > {({ startedAt }) => ` Loading since ${ startedAt .toISOString ()} ` }< / Async .Pending >
684700```
685701
686- ### ` <Fulfilled > ` / ` <Async.Fulfilled> `
702+ ### ` <IfFulfilled > ` / ` <Async.Fulfilled> `
687703
688704This component renders only when the promise is fulfilled (resolved to a value, could be ` undefined ` ).
689705
@@ -700,9 +716,9 @@ Alias: `<Async.Resolved>`
700716``` jsx
701717const state = useAsync (... )
702718return (
703- < Fulfilled state= {state}>
719+ < IfFulfilled state= {state}>
704720 {data => < pre> {JSON .stringify (data)}< / pre> }
705- < / Fulfilled >
721+ < / IfFulfilled >
706722)
707723```
708724
@@ -716,7 +732,7 @@ return (
716732< / Async .Fulfilled >
717733```
718734
719- ### ` <Rejected > ` / ` <Async.Rejected> `
735+ ### ` <IfRejected > ` / ` <Async.Rejected> `
720736
721737This component renders only when the promise is rejected.
722738
@@ -730,7 +746,7 @@ This component renders only when the promise is rejected.
730746
731747``` jsx
732748const state = useAsync (... )
733- return < Rejected state= {state}> Oops.< / Rejected >
749+ return < IfRejected state= {state}> Oops.< / IfRejected >
734750```
735751
736752``` jsx
@@ -741,7 +757,7 @@ return <Rejected state={state}>Oops.</Rejected>
741757< Async .Rejected > {error => ` Unexpected error: ${ error .message } ` }< / Async .Rejected >
742758```
743759
744- ### ` <Settled > ` / ` <Async.Settled> `
760+ ### ` <IfSettled > ` / ` <Async.Settled> `
745761
746762This component renders only when the promise is fulfilled or rejected.
747763
@@ -755,7 +771,7 @@ This component renders only when the promise is fulfilled or rejected.
755771
756772``` jsx
757773const state = useAsync (... )
758- return < Settled state= {state}> {state => ` Finished at ${ state .finishedAt .toISOString ()} ` < / Settled >
774+ return < IfSettled state= {state}> {state => ` Finished at ${ state .finishedAt .toISOString ()} ` < / IfSettled >
759775` ` `
760776
761777## Usage examples
0 commit comments