You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The shorthand version does not support passing additional props.
184
198
185
199
## API
186
200
187
201
### Props
188
202
189
203
`<Async>` takes the following properties:
190
204
191
-
-`promiseFn` {() => Promise} A function that returns a promise; invoked in `componentDidMount` and `componentDidUpdate`; receives props (object) as argument
192
-
-`deferFn` {() => Promise} A function that returns a promise; invoked only by calling `run`, with arguments being passed through, as well as props (object) as final argument
205
+
-`promiseFn` {(props, controller) => Promise} A function that returns a promise; invoked in `componentDidMount` and `componentDidUpdate`; receives component props (object) and AbortController instance as arguments
206
+
-`deferFn` {(...args, props, controller) => Promise} A function that returns a promise; invoked only by calling `run`, with arguments being passed through, as well as component props (object) and AbortController as final arguments
193
207
-`watch` {any} Watches this property through `componentDidUpdate` and re-runs the `promiseFn` when the value changes (`oldValue !== newValue`)
194
208
-`initialValue` {any} initial state for `data` or `error` (if instance of Error); useful for server-side rendering
195
209
-`onResolve` {Function} Callback function invoked when a promise resolves, receives data as argument
@@ -217,12 +231,12 @@ Similarly, this allows you to set default `onResolve` and `onReject` callbacks.
217
231
-`setData` {Function} sets `data` to the passed value, unsets `error` and cancels any pending promise
218
232
-`setError` {Function} sets `error` to the passed value and cancels any pending promise
219
233
220
-
### `useState`
234
+
### `useAsync`
221
235
222
-
The `useState` hook accepts an object with the same props as `<Async>`. Alternatively you can use the shorthand syntax:
236
+
The `useAsync` hook accepts an object with the same props as `<Async>`. Alternatively you can use the shorthand syntax:
223
237
224
238
```js
225
-
useState(promiseFn, initialValue)
239
+
useAsync(promiseFn, initialValue)
226
240
```
227
241
228
242
## Examples
@@ -424,4 +438,6 @@ Renders only while the deferred promise is still pending (not yet run).
424
438
425
439
## Acknowledgements
426
440
427
-
Many thanks to Andrey Popp for handing over ownership of `react-async` on npm.
441
+
Versions 1.x and 2.x of `react-async` on npm are from a different project abandoned years ago. The original author was
442
+
kind enough to transfer ownership so the `react-async` package name could be repurposed. The first version of
443
+
React Async is v3.0.0. Many thanks to Andrey Popp for handing over ownership of `react-async` on npm.
[](https://deploy.now.sh/?repo=https://github.com/ghengeveld/react-async/tree/master/examples/basic-fetch)
2
+
3
+
# Basic fetch with React Async
4
+
5
+
This demonstrates a very simple HTTP GET using `fetch`, wrapped with React Async.
0 commit comments