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
Copy file name to clipboardExpand all lines: README.md
+13-9Lines changed: 13 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -160,7 +160,7 @@ const MyComponent = () => (
160
160
161
161
> Similarly, this allows you to set default `onResolve` and `onReject` callbacks.
162
162
163
-
As a hook with `useAsync` (currently [only in React v16.7.0-alpha](https://reactjs.org/hooks)):
163
+
As a hook with `useAsync` (currently [only in React v16.7.0-alpha](https://reactjs.org/hooks); API is subject to change):
164
164
165
165
```js
166
166
import { useAsync } from"react-async"
@@ -194,7 +194,7 @@ const MyComponent = () => {
194
194
}
195
195
```
196
196
197
-
The shorthand version does not support passing additional props.
197
+
The shorthand version currently does not support passing additional props.
198
198
199
199
## API
200
200
@@ -203,7 +203,7 @@ The shorthand version does not support passing additional props.
203
203
`<Async>` takes the following properties:
204
204
205
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
206
+
-`deferFn` {(...args, props, controller) => Promise} A function that returns a promise; invoked only by calling `run(...args)`, with arguments being passed through, as well as component props (object) and AbortController as final arguments
207
207
-`watch` {any} Watches this property through `componentDidUpdate` and re-runs the `promiseFn` when the value changes (`oldValue !== newValue`)
208
208
-`initialValue` {any} initial state for `data` or `error` (if instance of Error); useful for server-side rendering
209
209
-`onResolve` {Function} Callback function invoked when a promise resolves, receives data as argument
@@ -225,20 +225,22 @@ The shorthand version does not support passing additional props.
225
225
-`isLoading` {boolean} `true` while a promise is pending
226
226
-`startedAt` {Date} when the current/last promise was started
227
227
-`finishedAt` {Date} when the last promise was resolved or rejected
228
-
-`cancel` {Function} ignores the result of the currently pending promise
228
+
-`cancel` {Function} ignores the result of the currently pending promise and calls `abort()` on the AbortController
229
229
-`run` {Function} runs the `deferFn`, passing any arguments provided
230
230
-`reload` {Function} re-runs the promise when invoked, using the previous arguments
231
231
-`setData` {Function} sets `data` to the passed value, unsets `error` and cancels any pending promise
232
232
-`setError` {Function} sets `error` to the passed value and cancels any pending promise
233
233
234
-
### `useAsync`
234
+
### `useAsync` (API may change until Hooks are officially released)
235
235
236
236
The `useAsync` hook accepts an object with the same props as `<Async>`. Alternatively you can use the shorthand syntax:
237
237
238
238
```js
239
239
useAsync(promiseFn, initialValue)
240
240
```
241
241
242
+
Note that the `useAsync` API is subject to change while Hooks are not officially released.
243
+
242
244
## Examples
243
245
244
246
### Basic data fetching with loading indicator, error state and retry
@@ -277,6 +279,8 @@ class App extends Component {
277
279
### Using `deferFn` to trigger an update (e.g. POST / PUT request)
0 commit comments