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 mutate filter functions documentation in v2 #340

Merged
merged 3 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions pages/docs/advanced/cache.en-US.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { Cache } from 'components/diagrams/cache'
When nested, SWR hooks will use the upper-level cache provider. If there is no upper-level cache provider, it fallbacks to the default cache provider, which is an empty `Map`.

<Callout emoji="⚠️">
If a cache provider is used, the global `mutate` will **not** work for SWR hooks under that `<SWRConfig>` boundary. Please use [this](#access-current-cache-provider) instead.
If a cache provider is used, the global `mutate` will **not** work for SWR hooks under that `<SWRConfig>` boundary. Please use [this](#access-current-cache-provider) instead.
</Callout>

## Access Current Cache Provider
Expand Down Expand Up @@ -187,13 +187,22 @@ describe('test suite', async () => {
})
```

### Access to the Cache
### Modify the Cache Data

Alert: you should not write to the cache directly, it might cause undefined behavior.
<Callout emoji="🚨" type="error">
You should not write to the cache directly, it might cause undefined behavior.
</Callout>

You can use [`mutate`](/docs/mutation) to modify the cache. For example, you can clear all cache data like the following.

```jsx
const { cache } = useSWRConfig()

cache.get(key) // Get the current data for a key.
cache.clear() // ⚠️ Clear all the cache. SWR will revalidate upon re-render.
mutate(
key => true, // which cache keys are updated
undefined, // update cache data to `undefined`
{ revalidate: false } // do not revalidate
)
```

More information can be found [here](/docs/arguments#multiple-arguments).
23 changes: 19 additions & 4 deletions pages/docs/advanced/cache.ja.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,28 @@ describe('test suite', async () => {
})
```

### キャッシュへアクセスする

警告:キャッシュに直接書き込むことはするべきではありません。予期しない動作が発生する可能性があります。
### キャッシュを更新する

```jsx
const { cache } = useSWRConfig()

cache.get(key) // キーの現在のデータを取得します。
cache.clear() // ⚠️ すべてのキャッシュをクリアします。 SWRは、再レンダリング時に再検証します。
```

<Callout emoji="🚨" type="error">
キャッシュに直接書き込むことはするべきではありません。予期しない動作が発生する可能性があります。
</Callout>

[`mutate`](/docs/mutation) をキャッシュを更新するために利用できます。例えば、下記のようにすることで全てのキャッシュデータをクリアできます。

```jsx
const { cache } = useSWRConfig()

mutate(
key => true, // どのキャッシュキーを更新するか
undefined, // キャッシュデータを `undefined` に更新する
{ revalidate: false } // 再検証しない
)
```

更なる情報は [こちら](/docs/arguments#multiple-arguments) から確認できます。
23 changes: 19 additions & 4 deletions pages/docs/advanced/cache.ko.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,28 @@ describe('test suite', async () => {
})
```

### 캐시에 접근하기

알림: 캐시를 직접 쓰면 안 됩니다. 정의되지 않은 동작을 유발할 수도 있습니다.
### Modify the Cache Data

```jsx
const { cache } = useSWRConfig()

cache.get(key) // 키에 대한 현재 데이터 가져오기.
cache.clear() // ⚠️ 모든 캐시를 삭제하기. SWR은 다시 렌더링할 때 재검증합니다.
```

<Callout emoji="🚨" type="error">
캐시를 직접 쓰면 안 됩니다. 정의되지 않은 동작을 유발할 수도 있습니다.
</Callout>

You can use [`mutate`](/docs/mutation) to modify the cache. For example, you can clear all cache data like the following.

```jsx
const { cache } = useSWRConfig()

mutate(
key => true, // which cache keys are updated
undefined, // update cache data to `undefined`
{ revalidate: false } // do not revalidate
)
```

More information can be found [here](/docs/arguments#multiple-arguments).
Loading