|
1 |
| -# react-async |
| 1 | +# <Async> |
2 | 2 |
|
3 |
| -React component for declarative promise resolution and data fetching. Uses render props for full flexibility or Context |
4 |
| -for convenience. Makes no assumptions about the shape of your data, the type of request or how you deal with loading |
5 |
| -states and errors. Supports optimistic updates. |
| 3 | +React component for declarative promise resolution and data fetching. Uses render props for full flexibility or React context |
| 4 | +for convenience. Makes it easy to handle loading and error states, without assumptions about the shape of your data or the type of request. Supports optimistic updates. |
6 | 5 |
|
7 | 6 | ## Install
|
8 | 7 |
|
@@ -68,26 +67,26 @@ const MyComponent = () => {
|
68 | 67 |
|
69 | 68 | `<Async>` takes the following properties:
|
70 | 69 |
|
71 |
| -- `promiseFn` [() => Promise] A function that returns a promise; invoked immediately in `componentDidMount` and without arguments |
72 |
| -- `deferFn` [() => Promise] A function that returns a promise; invoked only by calling `run`, with arguments being passed through |
73 |
| -- `watch` [any] Watches this property through `componentDidUpdate` and re-runs the `promiseFn` when the value changes (`oldValue !== newValue`) |
74 |
| -- `onResolve` [Function] Callback function invoked when a promise resolves, receives data as argument |
75 |
| -- `onReject` [Function] Callback function invoked when a promise rejects, receives error as argument |
| 70 | +- `promiseFn` {() => Promise} A function that returns a promise; invoked immediately in `componentDidMount` and without arguments |
| 71 | +- `deferFn` {() => Promise} A function that returns a promise; invoked only by calling `run`, with arguments being passed through |
| 72 | +- `watch` {any} Watches this property through `componentDidUpdate` and re-runs the `promiseFn` when the value changes (`oldValue !== newValue`) |
| 73 | +- `onResolve` {Function} Callback function invoked when a promise resolves, receives data as argument |
| 74 | +- `onReject` {Function} Callback function invoked when a promise rejects, receives error as argument |
76 | 75 |
|
77 | 76 | ### Render props
|
78 | 77 |
|
79 | 78 | `<Async>` provides the following render props:
|
80 | 79 |
|
81 |
| -- `data` [any] last resolved promise value, maintained when new error arrives |
82 |
| -- `error` [Error] rejected promise reason, cleared when new data arrives |
83 |
| -- `isLoading` [boolean] `true` while a promise is pending |
84 |
| -- `startedAt` [Date] when the current/last promise was started |
85 |
| -- `finishedAt` [Date] when the last promise was resolved or rejected |
86 |
| -- `cancel` [Function] ignores the result of the currently pending promise |
87 |
| -- `run` [Function] runs the `deferFn`, passing any arguments provided |
88 |
| -- `reload` [Function] re-runs the promise when invoked, using the previous arguments |
89 |
| -- `setData` [Function] sets `data` to the passed value, unsets `error` and cancels any pending promise |
90 |
| -- `setError` [Function] sets `error` to the passed value and cancels any pending promise |
| 80 | +- `data` {any} last resolved promise value, maintained when new error arrives |
| 81 | +- `error` {Error} rejected promise reason, cleared when new data arrives |
| 82 | +- `isLoading` {boolean} `true` while a promise is pending |
| 83 | +- `startedAt` {Date} when the current/last promise was started |
| 84 | +- `finishedAt` {Date} when the last promise was resolved or rejected |
| 85 | +- `cancel` {Function} ignores the result of the currently pending promise |
| 86 | +- `run` {Function} runs the `deferFn`, passing any arguments provided |
| 87 | +- `reload` {Function} re-runs the promise when invoked, using the previous arguments |
| 88 | +- `setData` {Function} sets `data` to the passed value, unsets `error` and cancels any pending promise |
| 89 | +- `setError` {Function} sets `error` to the passed value and cancels any pending promise |
91 | 90 |
|
92 | 91 | ## Examples
|
93 | 92 |
|
|
0 commit comments