@@ -67,7 +67,7 @@ Use it with `fetch`, Axios or other data fetching libraries, even GraphQL.
67
67
- Works with promises, async/await and the Fetch API
68
68
- Choose between Render Props, Context-based helper components or the ` useAsync ` and ` useFetch ` hooks
69
69
- Debug and develop every part of the loading sequence with the [ DevTools] ( #devtools )
70
- - Provides convenient ` isLoading ` , ` startedAt ` , ` finishedAt ` , et al metadata
70
+ - Provides convenient ` isPending ` , ` startedAt ` , ` finishedAt ` , et al metadata
71
71
- Provides ` cancel ` and ` reload ` actions
72
72
- Automatic re-run using ` watch ` or ` watchFn ` prop
73
73
- Accepts ` onResolve ` , ` onReject ` and ` onCancel ` callbacks
@@ -127,7 +127,7 @@ React Async is promise-based, so you can resolve anything you want, not just `fe
127
127
128
128
The React team is currently working on a large rewrite called [ Concurrent React] , previously known as "Async React".
129
129
Part of this rewrite is Suspense, which is a generic way for components to suspend rendering while they load data from
130
- a cache. It can render a fallback UI while loading data, much like ` <Async.Loading > ` .
130
+ a cache. It can render a fallback UI while loading data, much like ` <Async.Pending > ` .
131
131
132
132
React Async has no direct relation to Concurrent React. They are conceptually close, but not the same. React Async is
133
133
meant to make dealing with asynchronous business logic easier. Concurrent React will make those features have less
@@ -232,8 +232,8 @@ const loadCustomer = async ({ customerId }, { signal }) => {
232
232
}
233
233
234
234
const MyComponent = () => {
235
- const { data , error , isLoading } = useAsync ({ promiseFn: loadCustomer, customerId: 1 })
236
- if (isLoading ) return " Loading..."
235
+ const { data , error , isPending } = useAsync ({ promiseFn: loadCustomer, customerId: 1 })
236
+ if (isPending ) return " Loading..."
237
237
if (error) return ` Something went wrong: ${ error .message } `
238
238
if (data)
239
239
return (
@@ -253,7 +253,7 @@ Or using the shorthand version:
253
253
254
254
``` jsx
255
255
const MyComponent = () => {
256
- const { data , error , isLoading } = useAsync (loadCustomer, options)
256
+ const { data , error , isPending } = useAsync (loadCustomer, options)
257
257
// ...
258
258
}
259
259
```
@@ -267,7 +267,7 @@ import { useFetch } from "react-async"
267
267
268
268
const MyComponent = () => {
269
269
const headers = { Accept: " application/json" }
270
- const { data , error , isLoading , run } = useFetch (" /api/example" , { headers }, options)
270
+ const { data , error , isPending , run } = useFetch (" /api/example" , { headers }, options)
271
271
// This will setup a promiseFn with a fetch request and JSON deserialization.
272
272
273
273
// you can later call `run` with an optional callback argument to
@@ -315,8 +315,8 @@ const loadCustomer = ({ customerId }, { signal }) =>
315
315
316
316
const MyComponent = () => (
317
317
< Async promiseFn= {loadCustomer} customerId= {1 }>
318
- {({ data, error, isLoading }) => {
319
- if (isLoading ) return " Loading..."
318
+ {({ data, error, isPending }) => {
319
+ if (isPending ) return " Loading..."
320
320
if (error) return ` Something went wrong: ${ error .message } `
321
321
if (data)
322
322
return (
@@ -404,7 +404,7 @@ const loadCustomer = ({ customerId }, { signal }) =>
404
404
405
405
const MyComponent = () => (
406
406
< Async promiseFn= {loadCustomer} customerId= {1 }>
407
- < Async .Loading > Loading... < / Async .Loading >
407
+ < Async .Pending > Loading... < / Async .Pending >
408
408
< Async .Fulfilled >
409
409
{data => (
410
410
< div>
@@ -895,8 +895,8 @@ class App extends Component {
895
895
// The promiseFn should be defined outside of render()
896
896
return (
897
897
< Async promiseFn= {this .getSession } sessionId= {123 }>
898
- {({ data, error, isLoading , reload }) => {
899
- if (isLoading ) {
898
+ {({ data, error, isPending , reload }) => {
899
+ if (isPending ) {
900
900
return < div> Loading... < / div>
901
901
}
902
902
if (error) {
@@ -926,10 +926,10 @@ This uses `deferFn` to trigger an update (e.g. POST / PUT request) after a form
926
926
const subscribeToNewsletter = (args , props , controller ) => fetch (... )
927
927
928
928
< Async deferFn= {subscribeToNewsletter}>
929
- {({ error, isLoading , run }) => (
929
+ {({ error, isPending , run }) => (
930
930
< form onSubmit= {run}>
931
931
< input type= " email" name= " email" / >
932
- < button type= " submit" disabled= {isLoading }>
932
+ < button type= " submit" disabled= {isPending }>
933
933
Subscribe
934
934
< / button>
935
935
{error && < p> {error .toString ()}< / p> }
@@ -946,14 +946,14 @@ This uses both `promiseFn` and `deferFn` along with `setData` to implement optim
946
946
const updateAttendance = ([attend ]) => fetch (... ).then (() => attend, () => ! attend)
947
947
948
948
< Async promiseFn= {getAttendance} deferFn= {updateAttendance}>
949
- {({ data: isAttending, isLoading , run, setData }) => (
949
+ {({ data: isAttending, isPending , run, setData }) => (
950
950
< Toggle
951
951
on= {isAttending}
952
952
onClick= {() => {
953
953
setData (! isAttending)
954
954
run (! isAttending)
955
955
}}
956
- disabled= {isLoading }
956
+ disabled= {isPending }
957
957
/ >
958
958
)}
959
959
< / Async>
@@ -974,8 +974,8 @@ render() {
974
974
const { customers } = this .props // injected by getInitialProps
975
975
return (
976
976
< Async promiseFn= {loadCustomers} initialValue= {customers}>
977
- {({ data, error, isLoading , initialValue }) => { // initialValue is passed along for convenience
978
- if (isLoading ) {
977
+ {({ data, error, isPending , initialValue }) => { // initialValue is passed along for convenience
978
+ if (isPending ) {
979
979
return < div> Loading... < / div>
980
980
}
981
981
if (error) {
0 commit comments