From cb9597fecb419559ef01b066a393564782d53c56 Mon Sep 17 00:00:00 2001 From: Toru Kobayashi Date: Wed, 21 Sep 2022 21:19:49 +0900 Subject: [PATCH 1/4] explicit the location of mutate --- pages/docs/mutation.en-US.md | 14 +++++++++++++- pages/docs/mutation.es-ES.md | 14 +++++++++++++- pages/docs/mutation.ja.md | 14 +++++++++++++- pages/docs/mutation.ko.md | 14 +++++++++++++- pages/docs/mutation.pt-BR.md | 14 +++++++++++++- pages/docs/mutation.ru.md | 14 +++++++++++++- pages/docs/mutation.zh-CN.md | 14 +++++++++++++- 7 files changed, 91 insertions(+), 7 deletions(-) diff --git a/pages/docs/mutation.en-US.md b/pages/docs/mutation.en-US.md index ac6686b3..055fd7ff 100644 --- a/pages/docs/mutation.en-US.md +++ b/pages/docs/mutation.en-US.md @@ -5,7 +5,19 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -const data = await mutate(key, data, options) +import { mutate, useSWRConfig } from "swr" + +function App() { + // Or from the useSWRConfig hook + // const { mutate } = useSWRConfig() + const data = await mutate(key, data, options) +} +``` + +You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. + +```js +const { mutate } = useSWR(key, fetcher) ``` ### API diff --git a/pages/docs/mutation.es-ES.md b/pages/docs/mutation.es-ES.md index d81f753d..f46cd502 100644 --- a/pages/docs/mutation.es-ES.md +++ b/pages/docs/mutation.es-ES.md @@ -5,7 +5,19 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -const data = await mutate(key, data, options) +import { mutate, useSWRConfig } from "swr" + +function App() { + // Or from the useSWRConfig hook + // const { mutate } = useSWRConfig() + const data = await mutate(key, data, options) +} +``` + +You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. + +```js +const { mutate } = useSWR(key, fetcher) ``` ### API diff --git a/pages/docs/mutation.ja.md b/pages/docs/mutation.ja.md index dd6786ea..f50f49c9 100644 --- a/pages/docs/mutation.ja.md +++ b/pages/docs/mutation.ja.md @@ -5,7 +5,19 @@ SWR はリモートデータ及びキャッシュデータの更新のために ## mutate ```js -const data = await mutate(key, data, options) +import { mutate, useSWRConfig } from "swr" + +function App() { + // Or from the useSWRConfig hook + // const { mutate } = useSWRConfig() + const data = await mutate(key, data, options) +} +``` + +You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. + +```js +const { mutate } = useSWR(key, fetcher) ``` ### API diff --git a/pages/docs/mutation.ko.md b/pages/docs/mutation.ko.md index 397501f7..ce121750 100644 --- a/pages/docs/mutation.ko.md +++ b/pages/docs/mutation.ko.md @@ -5,7 +5,19 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -const data = await mutate(key, data, options) +import { mutate, useSWRConfig } from "swr" + +function App() { + // Or from the useSWRConfig hook + // const { mutate } = useSWRConfig() + const data = await mutate(key, data, options) +} +``` + +You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. + +```js +const { mutate } = useSWR(key, fetcher) ``` ### API diff --git a/pages/docs/mutation.pt-BR.md b/pages/docs/mutation.pt-BR.md index 140b4c5d..bfe82f9a 100644 --- a/pages/docs/mutation.pt-BR.md +++ b/pages/docs/mutation.pt-BR.md @@ -5,7 +5,19 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -const data = await mutate(key, data, options) +import { mutate, useSWRConfig } from "swr" + +function App() { + // Or from the useSWRConfig hook + // const { mutate } = useSWRConfig() + const data = await mutate(key, data, options) +} +``` + +You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. + +```js +const { mutate } = useSWR(key, fetcher) ``` ### API diff --git a/pages/docs/mutation.ru.md b/pages/docs/mutation.ru.md index 4f620dee..bb0cab58 100644 --- a/pages/docs/mutation.ru.md +++ b/pages/docs/mutation.ru.md @@ -5,7 +5,19 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -const data = await mutate(key, data, options) +import { mutate, useSWRConfig } from "swr" + +function App() { + // Or from the useSWRConfig hook + // const { mutate } = useSWRConfig() + const data = await mutate(key, data, options) +} +``` + +You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. + +```js +const { mutate } = useSWR(key, fetcher) ``` ### API diff --git a/pages/docs/mutation.zh-CN.md b/pages/docs/mutation.zh-CN.md index fcde26af..e517d7ed 100644 --- a/pages/docs/mutation.zh-CN.md +++ b/pages/docs/mutation.zh-CN.md @@ -5,7 +5,19 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -const data = await mutate(key, data, options) +import { mutate, useSWRConfig } from "swr" + +function App() { + // Or from the useSWRConfig hook + // const { mutate } = useSWRConfig() + const data = await mutate(key, data, options) +} +``` + +You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. + +```js +const { mutate } = useSWR(key, fetcher) ``` ### API From 8f8c804c87eaf1f528159baf9edb0bac62c36442 Mon Sep 17 00:00:00 2001 From: Toru Kobayashi Date: Wed, 21 Sep 2022 23:40:21 +0900 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Jiachi Liu --- pages/docs/mutation.en-US.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pages/docs/mutation.en-US.md b/pages/docs/mutation.en-US.md index 055fd7ff..cfa92501 100644 --- a/pages/docs/mutation.en-US.md +++ b/pages/docs/mutation.en-US.md @@ -5,16 +5,22 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -import { mutate, useSWRConfig } from "swr" +import { mutate as globalMutate, useSWRConfig } from "swr" function App() { // Or from the useSWRConfig hook - // const { mutate } = useSWRConfig() - const data = await mutate(key, data, options) + const { mutate } = useSWRConfig() + const data = mutate(key, data, options) + + // Or you can use globalMutate directly + // await globalMutate(key, data, options) + } ``` -You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data + +#### Example ```js const { mutate } = useSWR(key, fetcher) From 382ebef8b8b6cd5037996cbac90d4f5583f0b9c4 Mon Sep 17 00:00:00 2001 From: Toru Kobayashi Date: Wed, 21 Sep 2022 23:51:04 +0900 Subject: [PATCH 3/4] apply feedback to other languages --- pages/docs/mutation.en-US.md | 9 ++++----- pages/docs/mutation.es-ES.md | 15 ++++++++++----- pages/docs/mutation.ja.md | 15 ++++++++++----- pages/docs/mutation.ko.md | 15 ++++++++++----- pages/docs/mutation.pt-BR.md | 15 ++++++++++----- pages/docs/mutation.ru.md | 15 ++++++++++----- pages/docs/mutation.zh-CN.md | 15 ++++++++++----- 7 files changed, 64 insertions(+), 35 deletions(-) diff --git a/pages/docs/mutation.en-US.md b/pages/docs/mutation.en-US.md index cfa92501..f6229dc3 100644 --- a/pages/docs/mutation.en-US.md +++ b/pages/docs/mutation.en-US.md @@ -8,19 +8,18 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and import { mutate as globalMutate, useSWRConfig } from "swr" function App() { - // Or from the useSWRConfig hook const { mutate } = useSWRConfig() const data = mutate(key, data, options) - + // Or you can use globalMutate directly // await globalMutate(key, data, options) - + } ``` -[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. -#### Example +### Example ```js const { mutate } = useSWR(key, fetcher) diff --git a/pages/docs/mutation.es-ES.md b/pages/docs/mutation.es-ES.md index f46cd502..865944e8 100644 --- a/pages/docs/mutation.es-ES.md +++ b/pages/docs/mutation.es-ES.md @@ -5,16 +5,21 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -import { mutate, useSWRConfig } from "swr" +import { mutate as globalMutate, useSWRConfig } from "swr" function App() { - // Or from the useSWRConfig hook - // const { mutate } = useSWRConfig() - const data = await mutate(key, data, options) + const { mutate } = useSWRConfig() + const data = mutate(key, data, options) + + // Or you can use globalMutate directly + // await globalMutate(key, data, options) + } ``` -You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. + +### Example ```js const { mutate } = useSWR(key, fetcher) diff --git a/pages/docs/mutation.ja.md b/pages/docs/mutation.ja.md index f50f49c9..fd4ddbe1 100644 --- a/pages/docs/mutation.ja.md +++ b/pages/docs/mutation.ja.md @@ -5,16 +5,21 @@ SWR はリモートデータ及びキャッシュデータの更新のために ## mutate ```js -import { mutate, useSWRConfig } from "swr" +import { mutate as globalMutate, useSWRConfig } from "swr" function App() { - // Or from the useSWRConfig hook - // const { mutate } = useSWRConfig() - const data = await mutate(key, data, options) + const { mutate } = useSWRConfig() + const data = mutate(key, data, options) + + // または globalMutate を直接使うこともできます + // await globalMutate(key, data, options) + } ``` -You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. + +### Example ```js const { mutate } = useSWR(key, fetcher) diff --git a/pages/docs/mutation.ko.md b/pages/docs/mutation.ko.md index ce121750..e92cd15e 100644 --- a/pages/docs/mutation.ko.md +++ b/pages/docs/mutation.ko.md @@ -5,16 +5,21 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -import { mutate, useSWRConfig } from "swr" +import { mutate as globalMutate, useSWRConfig } from "swr" function App() { - // Or from the useSWRConfig hook - // const { mutate } = useSWRConfig() - const data = await mutate(key, data, options) + const { mutate } = useSWRConfig() + const data = mutate(key, data, options) + + // Or you can use globalMutate directly + // await globalMutate(key, data, options) + } ``` -You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. + +### Example ```js const { mutate } = useSWR(key, fetcher) diff --git a/pages/docs/mutation.pt-BR.md b/pages/docs/mutation.pt-BR.md index bfe82f9a..6d06ffb7 100644 --- a/pages/docs/mutation.pt-BR.md +++ b/pages/docs/mutation.pt-BR.md @@ -5,16 +5,21 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -import { mutate, useSWRConfig } from "swr" +import { mutate as globalMutate, useSWRConfig } from "swr" function App() { - // Or from the useSWRConfig hook - // const { mutate } = useSWRConfig() - const data = await mutate(key, data, options) + const { mutate } = useSWRConfig() + const data = mutate(key, data, options) + + // Or you can use globalMutate directly + // await globalMutate(key, data, options) + } ``` -You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. + +### Example ```js const { mutate } = useSWR(key, fetcher) diff --git a/pages/docs/mutation.ru.md b/pages/docs/mutation.ru.md index bb0cab58..2c4b0215 100644 --- a/pages/docs/mutation.ru.md +++ b/pages/docs/mutation.ru.md @@ -5,16 +5,21 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -import { mutate, useSWRConfig } from "swr" +import { mutate as globalMutate, useSWRConfig } from "swr" function App() { - // Or from the useSWRConfig hook - // const { mutate } = useSWRConfig() - const data = await mutate(key, data, options) + const { mutate } = useSWRConfig() + const data = mutate(key, data, options) + + // Or you can use globalMutate directly + // await globalMutate(key, data, options) + } ``` -You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. + +### Example ```js const { mutate } = useSWR(key, fetcher) diff --git a/pages/docs/mutation.zh-CN.md b/pages/docs/mutation.zh-CN.md index e517d7ed..53ecde4c 100644 --- a/pages/docs/mutation.zh-CN.md +++ b/pages/docs/mutation.zh-CN.md @@ -5,16 +5,21 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate ```js -import { mutate, useSWRConfig } from "swr" +import { mutate as globalMutate, useSWRConfig } from "swr" function App() { - // Or from the useSWRConfig hook - // const { mutate } = useSWRConfig() - const data = await mutate(key, data, options) + const { mutate } = useSWRConfig() + const data = mutate(key, data, options) + + // Or you can use globalMutate directly + // await globalMutate(key, data, options) + } ``` -You can get [bound mutate](/docs/mutation#bound-mutate) from `useSWR`. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. + +### Example ```js const { mutate } = useSWR(key, fetcher) From b50e4e82ac1c694f75cfaf11fb0ca23c1861bbdd Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 21 Sep 2022 17:25:34 +0200 Subject: [PATCH 4/4] add more descriptiong to mutation --- pages/docs/mutation.en-US.md | 10 ++++++++-- pages/docs/mutation.es-ES.md | 10 ++++++++-- pages/docs/mutation.ja.md | 10 ++++++++-- pages/docs/mutation.ko.md | 12 +++++++++--- pages/docs/mutation.pt-BR.md | 10 ++++++++-- pages/docs/mutation.ru.md | 11 ++++++++--- pages/docs/mutation.zh-CN.md | 10 ++++++++-- 7 files changed, 57 insertions(+), 16 deletions(-) diff --git a/pages/docs/mutation.en-US.md b/pages/docs/mutation.en-US.md index f6229dc3..8ef8abb2 100644 --- a/pages/docs/mutation.en-US.md +++ b/pages/docs/mutation.en-US.md @@ -4,6 +4,10 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate +There're 2 ways to use the `mutate` API to mutate the data, the global mutate API which can mutate any key and the bound mutate API which only can mutate the data of corresponding SWR hook. + +#### Global Mutate + ```js import { mutate as globalMutate, useSWRConfig } from "swr" @@ -16,13 +20,15 @@ function App() { } ``` +#### Bound Mutate -[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. Which `key` is bounded to the `key` passing to SWR, and receive the `data` as the first argument. -### Example ```js const { mutate } = useSWR(key, fetcher) + +await mutate(data) ``` ### API diff --git a/pages/docs/mutation.es-ES.md b/pages/docs/mutation.es-ES.md index 865944e8..5809b516 100644 --- a/pages/docs/mutation.es-ES.md +++ b/pages/docs/mutation.es-ES.md @@ -4,6 +4,10 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate +There're 2 ways to use the `mutate` API to mutate the data, the global mutate API which can mutate any key and the bound mutate API which only can mutate the data of corresponding SWR hook. + +#### Global Mutate + ```js import { mutate as globalMutate, useSWRConfig } from "swr" @@ -16,13 +20,15 @@ function App() { } ``` +#### Bound Mutate -[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. Which `key` is bounded to the `key` passing to SWR, and receive the `data` as the first argument. -### Example ```js const { mutate } = useSWR(key, fetcher) + +await mutate(data) ``` ### API diff --git a/pages/docs/mutation.ja.md b/pages/docs/mutation.ja.md index fd4ddbe1..1cfd5bb9 100644 --- a/pages/docs/mutation.ja.md +++ b/pages/docs/mutation.ja.md @@ -4,6 +4,10 @@ SWR はリモートデータ及びキャッシュデータの更新のために ## mutate +There're 2 ways to use the `mutate` API to mutate the data, the global mutate API which can mutate any key and the bound mutate API which only can mutate the data of corresponding SWR hook. + +#### Global Mutate + ```js import { mutate as globalMutate, useSWRConfig } from "swr" @@ -16,13 +20,15 @@ function App() { } ``` +#### Bound Mutate -[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. Which `key` is bounded to the `key` passing to SWR, and receive the `data` as the first argument. -### Example ```js const { mutate } = useSWR(key, fetcher) + +await mutate(data) ``` ### API diff --git a/pages/docs/mutation.ko.md b/pages/docs/mutation.ko.md index e92cd15e..d2ea8c2e 100644 --- a/pages/docs/mutation.ko.md +++ b/pages/docs/mutation.ko.md @@ -4,6 +4,10 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate +There're 2 ways to use the `mutate` API to mutate the data, the global mutate API which can mutate any key and the bound mutate API which only can mutate the data of corresponding SWR hook. + +#### Global Mutate + ```js import { mutate as globalMutate, useSWRConfig } from "swr" @@ -16,13 +20,15 @@ function App() { } ``` +#### Bound Mutate -[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. Which `key` is bounded to the `key` passing to SWR, and receive the `data` as the first argument. -### Example ```js const { mutate } = useSWR(key, fetcher) + +await mutate(data) ``` ### API @@ -145,7 +151,7 @@ function Profile () { 현재 데이터를 기반으로 데이터의 일부를 업데이트하려는 경우가 있습니다. -`mutate`를 사용해 현재 캐시 된 값을 받는(있으면 업데이트된 문서를 반환) 비동기 함수를 전달할 수 있습니다. +`mutate`를 사용해 현재 캐시 된 값을 받는(있으면 업데이트된 문서를 반환) 비동기 함수를 전달할 수 있습니다. ```jsx mutate('/api/todos', async todos => { diff --git a/pages/docs/mutation.pt-BR.md b/pages/docs/mutation.pt-BR.md index 6d06ffb7..e6c4c760 100644 --- a/pages/docs/mutation.pt-BR.md +++ b/pages/docs/mutation.pt-BR.md @@ -4,6 +4,10 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate +There're 2 ways to use the `mutate` API to mutate the data, the global mutate API which can mutate any key and the bound mutate API which only can mutate the data of corresponding SWR hook. + +#### Global Mutate + ```js import { mutate as globalMutate, useSWRConfig } from "swr" @@ -16,13 +20,15 @@ function App() { } ``` +#### Bound Mutate -[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. Which `key` is bounded to the `key` passing to SWR, and receive the `data` as the first argument. -### Example ```js const { mutate } = useSWR(key, fetcher) + +await mutate(data) ``` ### API diff --git a/pages/docs/mutation.ru.md b/pages/docs/mutation.ru.md index 2c4b0215..20a5d0b2 100644 --- a/pages/docs/mutation.ru.md +++ b/pages/docs/mutation.ru.md @@ -4,6 +4,10 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate +There're 2 ways to use the `mutate` API to mutate the data, the global mutate API which can mutate any key and the bound mutate API which only can mutate the data of corresponding SWR hook. + +#### Global Mutate + ```js import { mutate as globalMutate, useSWRConfig } from "swr" @@ -16,15 +20,16 @@ function App() { } ``` +#### Bound Mutate -[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. Which `key` is bounded to the `key` passing to SWR, and receive the `data` as the first argument. -### Example ```js const { mutate } = useSWR(key, fetcher) -``` +await mutate(data) +``` ### API #### Parameters diff --git a/pages/docs/mutation.zh-CN.md b/pages/docs/mutation.zh-CN.md index 53ecde4c..6f473e27 100644 --- a/pages/docs/mutation.zh-CN.md +++ b/pages/docs/mutation.zh-CN.md @@ -4,6 +4,10 @@ SWR provides the `mutate` and `useSWRMutation` APIs for mutating remote data and ## mutate +There're 2 ways to use the `mutate` API to mutate the data, the global mutate API which can mutate any key and the bound mutate API which only can mutate the data of corresponding SWR hook. + +#### Global Mutate + ```js import { mutate as globalMutate, useSWRConfig } from "swr" @@ -16,13 +20,15 @@ function App() { } ``` +#### Bound Mutate -[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. +[Bound Mutate](/docs/mutation#bound-mutate) is the short path to mutate the current key with data. Which `key` is bounded to the `key` passing to SWR, and receive the `data` as the first argument. -### Example ```js const { mutate } = useSWR(key, fetcher) + +await mutate(data) ``` ### API