Skip to content

Commit a0567e7

Browse files
ghengeveldgitbook-bot
authored andcommitted
GitBook: [next] 7 pages modified
1 parent 80585db commit a0567e7

File tree

7 files changed

+135
-194
lines changed

7 files changed

+135
-194
lines changed

gitbook/_summary.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# Summary
1+
# Table of contents
2+
3+
* [Introduction](introduction.md)
4+
* [Getting started](installation.md)
5+
* [Usage](usage.md)
6+
* [API](api.md)
7+
* [Helper components](helpers.md)
8+
* [DevTools](devtools.md)
29

3-
- [Introduction](introduction.md)
4-
- [Getting started](installation.md)
5-
- [Usage](usage.md)
6-
- [API](api.md)
7-
- [Helper components](helpers.md)
8-
- [DevTools](devtools.md)

gitbook/api.md

+72-108
Large diffs are not rendered by default.

gitbook/devtools.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# DevTools
22

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:
54

6-
```
5+
```text
76
npm install --save react-async-devtools
87
```
98

109
Or if you're using Yarn:
1110

12-
```
11+
```text
1312
yarn add react-async-devtools
1413
```
1514

@@ -25,3 +24,4 @@ export const Root = () => (
2524
</>
2625
)
2726
```
27+

gitbook/helpers.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Helper components
22

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.
54

65
## `<IfInitial>` / `<Async.Initial>`
76

87
Renders only while the deferred promise is still waiting to be run, or you have not provided any promise.
98

109
### Props
1110

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+
1515
as the promise starts loading.
1616

1717
### Examples
@@ -49,15 +49,15 @@ return (
4949

5050
## `<IfPending>` / `<Async.Pending>`
5151

52-
This component renders only while the promise is pending (loading / unsettled).
52+
This component renders only while the promise is pending \(loading / unsettled\).
5353

5454
Alias: `<Async.Loading>`
5555

5656
### Props
5757

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`\).
6161

6262
### Examples
6363

@@ -82,15 +82,15 @@ return (
8282

8383
## `<IfFulfilled>` / `<Async.Fulfilled>`
8484

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`\).
8686

8787
Alias: `<Async.Resolved>`
8888

8989
### Props
9090

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.
9494

9595
### Examples
9696

@@ -119,6 +119,7 @@ This component renders only when the promise is rejected.
119119

120120
### Props
121121

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.
125+

gitbook/installation.md

+19-16
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,51 @@
22

33
You can install `react-async` from npm:
44

5-
```
5+
```text
66
npm install --save react-async
77
```
88

99
Or if you're using Yarn:
1010

11-
```
11+
```text
1212
yarn add react-async
1313
```
1414

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.
1716
1817
## Upgrading
1918

2019
### Upgrade to v8
2120

2221
All standalone helper components were renamed to avoid import naming collision.
2322

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>`.
2928

3029
> A [codemod](https://github.com/async-library/react-async/tree/master/codemods) is available to automate the upgrade.
3130
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.
3432

3533
### Upgrade to v6
3634

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.
4038

4139
> A [codemod](https://github.com/async-library/react-async/tree/master/codemods) is available to automate the upgrade.
4240
4341
### Upgrade to v4
4442

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+
4645
of the arguments list. This enables better interop with TypeScript. You can use destructuring to keep using your
46+
4747
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+
4951
`initialValue`, but was undocumented and inflexible.
52+

gitbook/introduction.md

+5-19
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
11
# Introduction
22

3-
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.
64

75
## Rationale
86

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\).
138

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.
1710

1811
React Async is promise-based, so you can resolve anything you want, not just `fetch` requests.
1912

2013
## Concurrent React and Suspense
2114

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>`.
2516

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.
3118

32-
[concurrent react]: https://github.com/sw-yx/fresh-concurrent-react/blob/master/Intro.md#introduction-what-is-concurrent-react

gitbook/usage.md

+10-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# Usage
22

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.
54

65
## As a hook
76

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:
108

119
```jsx
1210
import { useAsync } from "react-async"
@@ -32,8 +30,7 @@ const MyComponent = () => {
3230
}
3331
```
3432

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.
3734
3835
Or using the shorthand version:
3936

@@ -77,18 +74,11 @@ const MyComponent = () => {
7774
}
7875
```
7976

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
84-
is set to `"application/json"`.
85-
86-
[fetch]: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
77+
`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"`.
8778

8879
## As a component
8980

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:
9282

9383
```jsx
9484
import Async from "react-async"
@@ -117,13 +107,11 @@ const MyComponent = () => (
117107
)
118108
```
119109

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.
122111
123112
## As a factory
124113

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.
127115

128116
```jsx
129117
import { createInstance } from "react-async"
@@ -145,9 +133,7 @@ const MyComponent = () => (
145133

146134
## With helper components
147135

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.
151137

152138
```jsx
153139
import { useAsync, IfPending, IfFulfilled, IfRejected } from "react-async"
@@ -177,8 +163,7 @@ const MyComponent = () => {
177163

178164
### As compounds to `<Async>`
179165

180-
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.
182167

183168
```jsx
184169
import Async from "react-async"
@@ -203,3 +188,4 @@ const MyComponent = () => (
203188
</Async>
204189
)
205190
```
191+

0 commit comments

Comments
 (0)