From 3dca0c0fc981f8b0378d1ee30b972a6aa572e313 Mon Sep 17 00:00:00 2001 From: Toru Kobayashi Date: Tue, 26 Jan 2021 00:37:13 +0900 Subject: [PATCH] docs: add revalidate in the documentation --- pages/docs/mutation.md | 30 ++++++++++++++++++++++++++++++ pages/docs/options.mdx | 11 ++++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/pages/docs/mutation.md b/pages/docs/mutation.md index 919e27ac..5cf87b6a 100644 --- a/pages/docs/mutation.md +++ b/pages/docs/mutation.md @@ -29,6 +29,36 @@ function App () { } ``` +You can also use the `revalidate` function that `useSWR` returns. + +```jsx +import useSWR from 'swr' + +function App () { + const { data, revalidate } = useSWR('/api/user', fetcher); + return ( +
+ + +
+ ) +} +``` + +`revalidate` accepts `retryCount` and `dedupe` as an option argument. + +```jsx +revalidate({ retryCount, dedupe }) +``` + ## Mutation and POST Request In many cases, applying local mutations to data is a good way to make changes diff --git a/pages/docs/options.mdx b/pages/docs/options.mdx index 74ab69a0..81cea636 100644 --- a/pages/docs/options.mdx +++ b/pages/docs/options.mdx @@ -8,15 +8,16 @@ const { data, error, isValidating, mutate } = useSWR(key, fetcher, options) ## Parameters -- `key`: a unique key string for the request (or a function / array / null) [(advanced usage)](/docs/conditional-fetching) -- `fetcher`: (_optional_) a Promise returning function to fetch your data [(details)](/docs/data-fetching) +- `key`: a unique key string for the request (or a function / array / null) [(advanced usage)](/docs/conditional-fetching) +- `fetcher`: (_optional_) a Promise returning function to fetch your data [(details)](/docs/data-fetching) - `options`: (_optional_) an object of options for this SWR hook ## Return Values -- `data`: data for the given key resolved by `fetcher` (or undefined if not loaded) -- `error`: error thrown by `fetcher` (or undefined) -- `isValidating`: if there's a request or revalidation loading +- `data`: data for the given key resolved by `fetcher` (or undefined if not loaded) +- `error`: error thrown by `fetcher` (or undefined) +- `isValidating`: if there's a request or revalidation loading - `mutate(data?, shouldRevalidate?)`: function to mutate the cached data +- `revalidate({ retryCount, dedupe }?)`: function to revalidate the data ## Options