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: gitbook/devtools.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,14 @@
1
1
# DevTools
2
2
3
-
React Async comes with a separate DevTools package which helps you Debug and develop your asynchronous application
4
-
states. You can install it from npm:
3
+
React Async comes with a separate DevTools package which helps you Debug and develop your asynchronous application states. You can install it from npm:
Copy file name to clipboardExpand all lines: gitbook/helpers.md
+17-16
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,17 @@
1
1
# Helper components
2
2
3
-
React Async provides several helper components that make your JSX more declarative and less cluttered.
4
-
They don't have to be direct children of `<Async>` and you can use the same component several times.
3
+
React Async provides several helper components that make your JSX more declarative and less cluttered. They don't have to be direct children of `<Async>` and you can use the same component several times.
5
4
6
5
## `<IfInitial>` / `<Async.Initial>`
7
6
8
7
Renders only while the deferred promise is still waiting to be run, or you have not provided any promise.
9
8
10
9
### Props
11
10
12
-
-`children``function(state: Object): Node | Node` Render function or React Node.
13
-
-`state``object` Async state object (return value of `useAsync()`).
14
-
-`persist``boolean` Show until we have data, even while loading or when an error occurred. By default it hides as soon
11
+
*`children``function(state: Object): Node | Node` Render function or React Node.
12
+
*`state``object` Async state object \(return value of `useAsync()`\).
13
+
*`persist``boolean` Show until we have data, even while loading or when an error occurred. By default it hides as soon
14
+
15
15
as the promise starts loading.
16
16
17
17
### Examples
@@ -49,15 +49,15 @@ return (
49
49
50
50
## `<IfPending>` / `<Async.Pending>`
51
51
52
-
This component renders only while the promise is pending (loading / unsettled).
52
+
This component renders only while the promise is pending \(loading / unsettled\).
53
53
54
54
Alias: `<Async.Loading>`
55
55
56
56
### Props
57
57
58
-
-`children``function(state: Object): Node | Node` Render function or React Node.
59
-
-`state``object` Async state object (return value of `useAsync()`).
60
-
-`initial``boolean` Show only on initial load (when `data` is `undefined`).
58
+
*`children``function(state: Object): Node | Node` Render function or React Node.
59
+
*`state``object` Async state object \(return value of `useAsync()`\).
60
+
*`initial``boolean` Show only on initial load \(when `data` is `undefined`\).
61
61
62
62
### Examples
63
63
@@ -82,15 +82,15 @@ return (
82
82
83
83
## `<IfFulfilled>` / `<Async.Fulfilled>`
84
84
85
-
This component renders only when the promise is fulfilled (resolved to a value, could be `undefined`).
85
+
This component renders only when the promise is fulfilled \(resolved to a value, could be `undefined`\).
86
86
87
87
Alias: `<Async.Resolved>`
88
88
89
89
### Props
90
90
91
-
-`children``function(data: any, state: Object): Node | Node` Render function or React Node.
92
-
-`state``object` Async state object (return value of `useAsync()`).
93
-
-`persist``boolean` Show old data while loading new data. By default it hides as soon as a new promise starts.
91
+
*`children``function(data: any, state: Object): Node | Node` Render function or React Node.
92
+
*`state``object` Async state object \(return value of `useAsync()`\).
93
+
*`persist``boolean` Show old data while loading new data. By default it hides as soon as a new promise starts.
94
94
95
95
### Examples
96
96
@@ -119,6 +119,7 @@ This component renders only when the promise is rejected.
119
119
120
120
### Props
121
121
122
-
-`children``function(error: Error, state: Object): Node | Node` Render function or React Node.
123
-
-`state``object` Async state object (return value of `useAsync()`).
124
-
-`persist``boolean` Show old error while loading new data. By default it hides as soon as a new promise starts.
122
+
*`children``function(error: Error, state: Object): Node | Node` Render function or React Node.
123
+
*`state``object` Async state object \(return value of `useAsync()`\).
124
+
*`persist``boolean` Show old error while loading new data. By default it hides as soon as a new promise starts.
Copy file name to clipboardExpand all lines: gitbook/installation.md
+19-16
Original file line number
Diff line number
Diff line change
@@ -2,48 +2,51 @@
2
2
3
3
You can install `react-async` from npm:
4
4
5
-
```
5
+
```text
6
6
npm install --save react-async
7
7
```
8
8
9
9
Or if you're using Yarn:
10
10
11
-
```
11
+
```text
12
12
yarn add react-async
13
13
```
14
14
15
-
> This package requires `react` as a peer dependency. Please make sure to install that as well.
16
-
> If you want to use the `useAsync` hook, you'll need `[email protected]` or later.
15
+
> This package requires `react` as a peer dependency. Please make sure to install that as well. If you want to use the `useAsync` hook, you'll need `[email protected]` or later.
17
16
18
17
## Upgrading
19
18
20
19
### Upgrade to v8
21
20
22
21
All standalone helper components were renamed to avoid import naming collision.
23
22
24
-
-`<Initial>` was renamed to `<IfInitial>`.
25
-
-`<Pending>` was renamed to `<IfPending>`.
26
-
-`<Fulfilled>` was renamed to `<IfFulfilled>`.
27
-
-`<Rejected>` was renamed to `<IfRejected`.
28
-
-`<Settled>` was renamed to `<IfSettled>`.
23
+
*`<Initial>` was renamed to `<IfInitial>`.
24
+
*`<Pending>` was renamed to `<IfPending>`.
25
+
*`<Fulfilled>` was renamed to `<IfFulfilled>`.
26
+
*`<Rejected>` was renamed to `<IfRejected`.
27
+
*`<Settled>` was renamed to `<IfSettled>`.
29
28
30
29
> A [codemod](https://github.com/async-library/react-async/tree/master/codemods) is available to automate the upgrade.
31
30
32
-
The return type for `run` was changed from `Promise` to `undefined`. You should now use the `promise` prop instead. This
33
-
is a manual upgrade. See [`promise`](#promise-1) for details.
31
+
The return type for `run` was changed from `Promise` to `undefined`. You should now use the `promise` prop instead. This is a manual upgrade. See [`promise`](installation.md#promise-1) for details.
34
32
35
33
### Upgrade to v6
36
34
37
-
-`<Async.Pending>` was renamed to `<Async.Initial>`.
38
-
- Some of the other helpers were also renamed, but the old ones remain as alias.
39
-
- Don't forget to deal with any custom instances of `<Async>` when upgrading.
35
+
*`<Async.Pending>` was renamed to `<Async.Initial>`.
36
+
* Some of the other helpers were also renamed, but the old ones remain as alias.
37
+
* Don't forget to deal with any custom instances of `<Async>` when upgrading.
40
38
41
39
> A [codemod](https://github.com/async-library/react-async/tree/master/codemods) is available to automate the upgrade.
42
40
43
41
### Upgrade to v4
44
42
45
-
-`deferFn` now receives an `args` array as the first argument, instead of arguments to `run` being spread at the front
43
+
*`deferFn` now receives an `args` array as the first argument, instead of arguments to `run` being spread at the front
44
+
46
45
of the arguments list. This enables better interop with TypeScript. You can use destructuring to keep using your
46
+
47
47
existing variables.
48
-
- The shorthand version of `useAsync` now takes the `options` object as optional second argument. This used to be
48
+
49
+
* The shorthand version of `useAsync` now takes the `options` object as optional second argument. This used to be
50
+
49
51
`initialValue`, but was undocumented and inflexible.
React Async is a utility belt for declarative promise resolution and data fetching. It makes it easy to handle
4
-
asynchronous UI states, without assumptions about the shape of your data or the type of request. React Async consists of
5
-
a React component and several hooks. You can use it with `fetch`, Axios or other data fetching libraries, even GraphQL.
3
+
React Async is a utility belt for declarative promise resolution and data fetching. It makes it easy to handle asynchronous UI states, without assumptions about the shape of your data or the type of request. React Async consists of a React component and several hooks. You can use it with `fetch`, Axios or other data fetching libraries, even GraphQL.
6
4
7
5
## Rationale
8
6
9
-
React Async is different in that it tries to resolve data as close as possible to where it will be used, while using
10
-
declarative syntax, using just JSX and native promises. This is in contrast to systems like Redux where you would
11
-
configure any data fetching or updates on a higher (application global) level, using a special construct
12
-
(actions/reducers).
7
+
React Async is different in that it tries to resolve data as close as possible to where it will be used, while using declarative syntax, using just JSX and native promises. This is in contrast to systems like Redux where you would configure any data fetching or updates on a higher \(application global\) level, using a special construct \(actions/reducers\).
13
8
14
-
React Async works well even in larger applications with multiple or nested data dependencies. It encourages loading
15
-
data on-demand and in parallel at component level instead of in bulk at the route/page level. It's entirely decoupled
16
-
from your routes, so it works well in complex applications that have a dynamic routing model or don't use routes at all.
9
+
React Async works well even in larger applications with multiple or nested data dependencies. It encourages loading data on-demand and in parallel at component level instead of in bulk at the route/page level. It's entirely decoupled from your routes, so it works well in complex applications that have a dynamic routing model or don't use routes at all.
17
10
18
11
React Async is promise-based, so you can resolve anything you want, not just `fetch` requests.
19
12
20
13
## Concurrent React and Suspense
21
14
22
-
The React team is currently working on a large rewrite called [Concurrent React], previously known as "Async React".
23
-
Part of this rewrite is Suspense, which is a generic way for components to suspend rendering while they load data from
24
-
a cache. It can render a fallback UI while loading data, much like `<Async.Pending>`.
15
+
The React team is currently working on a large rewrite called [Concurrent React](https://github.com/sw-yx/fresh-concurrent-react/blob/master/Intro.md#introduction-what-is-concurrent-react), previously known as "Async React". Part of this rewrite is Suspense, which is a generic way for components to suspend rendering while they load data from a cache. It can render a fallback UI while loading data, much like `<Async.Pending>`.
25
16
26
-
React Async has no direct relation to Concurrent React. They are conceptually close, but not the same. React Async is
27
-
meant to make dealing with asynchronous business logic easier. Concurrent React will make those features have less
28
-
impact on performance and usability. When Suspense lands, React Async will make full use of Suspense features. In fact,
29
-
you can already **start using React Async right now**, and in a later update, you'll **get Suspense features for free**.
30
-
In fact, React Async already has experimental support for Suspense, by passing the `suspense` option.
17
+
React Async has no direct relation to Concurrent React. They are conceptually close, but not the same. React Async is meant to make dealing with asynchronous business logic easier. Concurrent React will make those features have less impact on performance and usability. When Suspense lands, React Async will make full use of Suspense features. In fact, you can already **start using React Async right now**, and in a later update, you'll **get Suspense features for free**. In fact, React Async already has experimental support for Suspense, by passing the `suspense` option.
Copy file name to clipboardExpand all lines: gitbook/usage.md
+10-24
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,10 @@
1
1
# Usage
2
2
3
-
React Async offers three primary APIs: the `useAsync` hook, the `<Async>` component and the `createInstance`
4
-
factory function. Each has its unique benefits and downsides.
3
+
React Async offers three primary APIs: the `useAsync` hook, the `<Async>` component and the `createInstance` factory function. Each has its unique benefits and downsides.
5
4
6
5
## As a hook
7
6
8
-
The `useAsync` hook (available [from React v16.8.0](https://reactjs.org/hooks)) offers direct access to React Async's
9
-
core functionality from within your own function components:
7
+
The `useAsync` hook \(available [from React v16.8.0](https://reactjs.org/hooks)\) offers direct access to React Async's core functionality from within your own function components:
10
8
11
9
```jsx
12
10
import { useAsync } from"react-async"
@@ -32,8 +30,7 @@ const MyComponent = () => {
32
30
}
33
31
```
34
32
35
-
> Using [helper components](#with-helper-components) can greatly improve readability of your render functions by not
36
-
> having to write all those conditional returns.
33
+
> Using [helper components](usage.md#with-helper-components) can greatly improve readability of your render functions by not having to write all those conditional returns.
37
34
38
35
Or using the shorthand version:
39
36
@@ -77,18 +74,11 @@ const MyComponent = () => {
77
74
}
78
75
```
79
76
80
-
`useFetch` takes the same arguments as [fetch] itself, as well as `options` to the underlying `useAsync` hook. The
81
-
`options` object takes two special boolean properties: `defer` and `json`. These can be used to switch between
82
-
`deferFn` and `promiseFn`, and enable JSON parsing. By default `useFetch` automatically uses `promiseFn` or `deferFn`
83
-
based on the request method (`deferFn` for POST / PUT / PATCH / DELETE) and handles JSON parsing if the `Accept` header
`useFetch` takes the same arguments as [fetch](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) itself, as well as `options` to the underlying `useAsync` hook. The `options` object takes two special boolean properties: `defer` and `json`. These can be used to switch between `deferFn` and `promiseFn`, and enable JSON parsing. By default `useFetch` automatically uses `promiseFn` or `deferFn` based on the request method \(`deferFn` for POST / PUT / PATCH / DELETE\) and handles JSON parsing if the `Accept` header is set to `"application/json"`.
87
78
88
79
## As a component
89
80
90
-
The classic interface to React Async. Simply use `<Async>` directly in your JSX component tree, leveraging the render
91
-
props pattern:
81
+
The classic interface to React Async. Simply use `<Async>` directly in your JSX component tree, leveraging the render props pattern:
92
82
93
83
```jsx
94
84
importAsyncfrom"react-async"
@@ -117,13 +107,11 @@ const MyComponent = () => (
117
107
)
118
108
```
119
109
120
-
> Using [helper components](#with-helper-components) can greatly improve readability of your render functions by not
121
-
> having to write all those conditional returns.
110
+
> Using [helper components](usage.md#with-helper-components) can greatly improve readability of your render functions by not having to write all those conditional returns.
122
111
123
112
## As a factory
124
113
125
-
You can also create your own component instances, allowing you to preconfigure them with options such as default
126
-
`onResolve` and `onReject` callbacks.
114
+
You can also create your own component instances, allowing you to preconfigure them with options such as default `onResolve` and `onReject` callbacks.
127
115
128
116
```jsx
129
117
import { createInstance } from"react-async"
@@ -145,9 +133,7 @@ const MyComponent = () => (
145
133
146
134
## With helper components
147
135
148
-
Several [helper components](#helper-components) are available to improve legibility. They can be used with `useAsync`
149
-
by passing in the state, or with `<Async>` by using Context. Each of these components simply enables or disables
150
-
rendering of its children based on the current state.
136
+
Several [helper components](usage.md#helper-components) are available to improve legibility. They can be used with `useAsync` by passing in the state, or with `<Async>` by using Context. Each of these components simply enables or disables rendering of its children based on the current state.
Each of the helper components are also available as static properties of `<Async>`. In this case you won't have to pass
181
-
the state object, instead it will be automatically provided through Context.
166
+
Each of the helper components are also available as static properties of `<Async>`. In this case you won't have to pass the state object, instead it will be automatically provided through Context.
0 commit comments