Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add isLoading and keepPreviousData pages in v2 #343

Merged
merged 25 commits into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a151bbe
docs: add the Return Values page
koba04 Aug 24, 2022
1a816e0
docs: add isLoading and keepPreviousData option
koba04 Aug 27, 2022
3d31ece
docs: fix header levels
koba04 Aug 27, 2022
59340e6
docs: add a video for keepPreviousData
koba04 Aug 27, 2022
93eef90
docs: move arguments page to next to return values page
koba04 Aug 30, 2022
e2274cc
docs: update diagrams for returning values
koba04 Aug 30, 2022
ef9ee10
docs: update the performance document to add isLoading
koba04 Aug 31, 2022
fc18ba8
docs: keep the list of return values in the options document
koba04 Aug 31, 2022
b2429c5
use isLoading instead of !data
koba04 Aug 31, 2022
da4caf7
translate options.md into Japanese
koba04 Aug 31, 2022
16abf5b
docs: add a detail link for keepPreviousData
koba04 Sep 1, 2022
8c8ba4f
tweak the description of isLoading
koba04 Sep 1, 2022
41f49dc
revert to move the arguments page
koba04 Sep 2, 2022
3509408
move the return values page into the advanced section
koba04 Sep 2, 2022
c363774
rename the Options page to API Options
koba04 Sep 2, 2022
358eccc
fix links to the return values
koba04 Sep 2, 2022
2dd5497
fix a typo
koba04 Sep 2, 2022
7f79c09
add an excalidraw file for the state machine diagrams
koba04 Sep 3, 2022
c5758bf
rename the page from Return Values to Understanding SWR
koba04 Sep 3, 2022
a07951f
rename the Options page to API
koba04 Sep 3, 2022
83f0d81
translate Understanding SWR into Japanese
koba04 Sep 3, 2022
33814f1
tweak
koba04 Sep 3, 2022
5c01f41
change /docs/options links to /docs/api
koba04 Sep 3, 2022
21f0e80
Update pages/docs/advanced/meta.en-US.json
koba04 Sep 4, 2022
2e5b289
change the link of Understanding SWR
koba04 Sep 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5,744 changes: 5,744 additions & 0 deletions components/excalidraw/state-machine.excalidraw

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ module.exports = withNextra({
destination: "/docs/advanced/cache",
statusCode: 301,
},
{
source: "/docs/options",
destination: "/docs/api",
statusCode: 301
},
{
source: "/change-log",
destination: "/docs/change-log",
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/advanced/meta.en-US.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"return-values": "Return Values",
"understanding-swr": "Understanding SWR",
koba04 marked this conversation as resolved.
Show resolved Hide resolved
"cache": "Cache",
"performance": "Performance",
"react-native": "React Native",
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/advanced/meta.es-ES.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"return-values": "Valores devueltos",
"understanding-swr": "Understanding SWR",
"cache": "Cache",
"performance": "Rendimiento",
"react-native": "React Native",
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/advanced/meta.ja.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"return-values": "返り値",
"understanding-swr": "Understanding SWR",
"cache": "キャッシュ",
"performance": "パフォーマンス",
"react-native": "React Native",
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/advanced/meta.ko.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"return-values": "반환 값",
"understanding-swr": "Understanding SWR",
"cache": "캐시",
"performance": "성능",
"react-native": "React Native",
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/advanced/meta.pt-BR.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"return-values": "Valores Retornados",
"understanding-swr": "Understanding SWR",
"cache": "Cache",
"performance": "Desempenho",
"react-native": "React Native",
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/advanced/meta.ru.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"return-values": "Возвращаемые значения",
"understanding-swr": "Understanding SWR",
"cache": "Кеш",
"performance": "Производительность",
"react-native": "React Native",
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/advanced/meta.zh-CN.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"return-values": "返回值",
"understanding-swr": "Understanding SWR",
"cache": "缓存",
"performance": "性能",
"react-native": "React Native",
Expand Down
84 changes: 0 additions & 84 deletions pages/docs/advanced/return-values.pt-BR.mdx

This file was deleted.

84 changes: 0 additions & 84 deletions pages/docs/advanced/return-values.ru.mdx

This file was deleted.

84 changes: 0 additions & 84 deletions pages/docs/advanced/return-values.zh-CN.mdx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import Video from 'components/video'

# Return Values
# Understanding SWR

## The Patterns of the Return Values
## State Machine

`useSWR` returns `data`, `error`, `isLoading`, and `isValidating` depending on the state of the `fetcher` function. This diagrams describe how SWR returns values in some scenarios.

### Fetch and Revalidate

This pattern is to fetch data and revalidate it later.

![A pattern for fetch and revalidate](/img/return-values/fetch-and-revalidate.svg)
![A pattern for fetch and revalidate](/img/understanding-swr/fetch-and-revalidate.svg)

### Key Change

This pattern is to fetch data and change the key and revalidate it later.

![A pattern for key change](/img/return-values/key-change.svg)
![A pattern for key change](/img/understanding-swr/key-change.svg)

### Key Change + Previous Data

This pattern is to fetch data and change the key and revalidate it later with the `keepPreviousData` option.

![A pattern for key change + previous data](/img/return-values/key-change-previous-data.svg)
![A pattern for key change + previous data](/img/understanding-swr/key-change-previous-data.svg)

### Fallback

This pattern is to fetch data and revalidate it later with fallback data.

![A pattern for fallback](/img/return-values/fallback.svg)
![A pattern for fallback](/img/understanding-swr/fallback.svg)

### Key Change + Fallback

This pattern is to fetch data and change the key and revalidate it later with fallback data.

![A pattern for key change + fallback](/img/return-values/key-change-fallback.svg)
![A pattern for key change + fallback](/img/understanding-swr/key-change-fallback.svg)

### Key Change + Previous Data + Fallback

This pattern is to fetch data and change the key and revalidate it later with the `keepPreviousData` option and fallback data.

![A pattern for key change + previous data + fallback](/img/return-values/key-change-previous-data-fallback.svg)
![A pattern for key change + previous data + fallback](/img/understanding-swr/key-change-previous-data-fallback.svg)

## Return previous data for better UX

Expand Down Expand Up @@ -81,4 +81,4 @@ With `keepPreviousData` enabled, you will still get the previous data even if yo

## Dependency Collection for performance

SWR only updates the states that are used by a component. If you only use `data` in the component, SWR ignores the updates of other properties like `isValidating`, and `isLoading`. This reduces rendering counts a lot. More information can be found [here](/docs/advanced/performance#dependency-collection).
SWR only triggers re-rendering when the states used in the component have been updated. If you only use `data` in the component, SWR ignores the updates of other properties like `isValidating`, and `isLoading`. This reduces rendering counts a lot. More information can be found [here](/docs/advanced/performance#dependency-collection).