From 2094bc034229740714cc6d9176d118f7105dc936 Mon Sep 17 00:00:00 2001 From: Joel Tio Date: Thu, 18 Jul 2024 12:55:23 +0800 Subject: [PATCH] docs: clarify usage of useSWRMutation with optimisticData --- pages/docs/mutation.en-US.mdx | 3 +++ pages/docs/mutation.es-ES.mdx | 3 +++ pages/docs/mutation.fr-FR.mdx | 3 +++ pages/docs/mutation.ja.mdx | 3 +++ pages/docs/mutation.ko.mdx | 3 +++ pages/docs/mutation.pt-BR.mdx | 3 +++ pages/docs/mutation.ru.mdx | 3 +++ pages/docs/mutation.zh-CN.mdx | 3 +++ 8 files changed, 24 insertions(+) diff --git a/pages/docs/mutation.en-US.mdx b/pages/docs/mutation.en-US.mdx index 1c7a70bc..b3035522 100644 --- a/pages/docs/mutation.en-US.mdx +++ b/pages/docs/mutation.en-US.mdx @@ -328,6 +328,7 @@ import useSWRMutation from 'swr/mutation' function Profile () { const { trigger } = useSWRMutation('/api/user', updateUserName) + const { data } = useSWR('/api/user', fetcher) return (
@@ -344,6 +345,8 @@ function Profile () { ) } ``` +Note that the value provided for `optimisticData` should be based on the data +returned from `useSWR` as opposed to `useSWRMutation`'s data. ## Rollback on Errors [#rollback-on-errors] diff --git a/pages/docs/mutation.es-ES.mdx b/pages/docs/mutation.es-ES.mdx index 2c9a8c4e..74fc5203 100644 --- a/pages/docs/mutation.es-ES.mdx +++ b/pages/docs/mutation.es-ES.mdx @@ -329,6 +329,7 @@ import useSWRMutation from 'swr/mutation' function Profile () { const { trigger } = useSWRMutation('/api/user', updateUserName) + const { data } = useSWR('/api/user', fetcher) return (
@@ -345,6 +346,8 @@ function Profile () { ) } ``` +Note that the value provided for `optimisticData` should be based on the data +returned from `useSWR` as opposed to `useSWRMutation`'s data. ## Rollback on Errors [#rollback-on-errors] diff --git a/pages/docs/mutation.fr-FR.mdx b/pages/docs/mutation.fr-FR.mdx index 39791529..9f40cc87 100644 --- a/pages/docs/mutation.fr-FR.mdx +++ b/pages/docs/mutation.fr-FR.mdx @@ -323,6 +323,7 @@ import useSWRMutation from 'swr/mutation' function Profile () { const { trigger } = useSWRMutation('/api/user', updateUserName) + const { data } = useSWR('/api/user', fetcher) return (
@@ -339,6 +340,8 @@ function Profile () { ) } ``` +Note that the value provided for `optimisticData` should be based on the data +returned from `useSWR` as opposed to `useSWRMutation`'s data. ## Revenir en arrière sur les erreurs [#rollback-on-errors] diff --git a/pages/docs/mutation.ja.mdx b/pages/docs/mutation.ja.mdx index c05145f3..678ba153 100644 --- a/pages/docs/mutation.ja.mdx +++ b/pages/docs/mutation.ja.mdx @@ -329,6 +329,7 @@ import useSWRMutation from 'swr/mutation' function Profile () { const { trigger } = useSWRMutation('/api/user', updateUserName) + const { data } = useSWR('/api/user', fetcher) return (
@@ -345,6 +346,8 @@ function Profile () { ) } ``` +Note that the value provided for `optimisticData` should be based on the data +returned from `useSWR` as opposed to `useSWRMutation`'s data. ## エラー時のロールバック [#rollback-on-errors] diff --git a/pages/docs/mutation.ko.mdx b/pages/docs/mutation.ko.mdx index 87819780..5586a7b2 100644 --- a/pages/docs/mutation.ko.mdx +++ b/pages/docs/mutation.ko.mdx @@ -328,6 +328,7 @@ import useSWRMutation from 'swr/mutation' function Profile () { const { trigger } = useSWRMutation('/api/user', updateUserName) + const { data } = useSWR('/api/user', fetcher) return (
@@ -344,6 +345,8 @@ function Profile () { ) } ``` +Note that the value provided for `optimisticData` should be based on the data +returned from `useSWR` as opposed to `useSWRMutation`'s data. ## 오류 시 롤백 [#rollback-on-errors] diff --git a/pages/docs/mutation.pt-BR.mdx b/pages/docs/mutation.pt-BR.mdx index 455ad0ce..d0b822a0 100644 --- a/pages/docs/mutation.pt-BR.mdx +++ b/pages/docs/mutation.pt-BR.mdx @@ -323,6 +323,7 @@ import useSWRMutation from 'swr/mutation' function Profile () { const { trigger } = useSWRMutation('/api/user', updateUserName) + const { data } = useSWR('/api/user', fetcher) return (
@@ -339,6 +340,8 @@ function Profile () { ) } ``` +Note that the value provided for `optimisticData` should be based on the data +returned from `useSWR` as opposed to `useSWRMutation`'s data. ## Reversão de Erros [#rollback-on-errors] diff --git a/pages/docs/mutation.ru.mdx b/pages/docs/mutation.ru.mdx index 6844ab0d..a5bf2ead 100644 --- a/pages/docs/mutation.ru.mdx +++ b/pages/docs/mutation.ru.mdx @@ -328,6 +328,7 @@ import useSWRMutation from 'swr/mutation' function Profile () { const { trigger } = useSWRMutation('/api/user', updateUserName) + const { data } = useSWR('/api/user', fetcher) return (
@@ -344,6 +345,8 @@ function Profile () { ) } ``` +Note that the value provided for `optimisticData` should be based on the data +returned from `useSWR` as opposed to `useSWRMutation`'s data. ## Откат при ошибках [#rollback-on-errors] diff --git a/pages/docs/mutation.zh-CN.mdx b/pages/docs/mutation.zh-CN.mdx index 0db4cf56..04dedfc6 100644 --- a/pages/docs/mutation.zh-CN.mdx +++ b/pages/docs/mutation.zh-CN.mdx @@ -323,6 +323,7 @@ import useSWRMutation from 'swr/mutation' function Profile () { const { trigger } = useSWRMutation('/api/user', updateUserName) + const { data } = useSWR('/api/user', fetcher) return (
@@ -339,6 +340,8 @@ function Profile () { ) } ``` +Note that the value provided for `optimisticData` should be based on the data +returned from `useSWR` as opposed to `useSWRMutation`'s data. ## 错误回滚 [#rollback-on-errors]