Skip to content

Commit 22970b8

Browse files
devplaijjk
andauthored
docs(use-cache): add missing switcher code blocks and types in examples (vercel#74083)
Hi Team. This PR updates the use cache directive documentation with the following changes: - Added switcher code blocks for `next.config.ts` and `next.config.js` examples. - Updated missing `switcher` for `Bookings` component examples to include switcher support. - Added missing types for `ClientComponent` of tsx block. Co-authored-by: JJ Kasper <jj@jjsweb.site>
1 parent bf02ac3 commit 22970b8

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

docs/01-app/04-api-reference/01-directives/use-cache.mdx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The `use cache` directive designates a component and/or a function to be cached.
1919

2020
Enable support for the `use cache` directive with the [`dynamicIO`](/docs/app/api-reference/config/next-config-js/dynamicIO) flag in your `next.config.ts` file:
2121

22-
```ts filename="next.config.ts"
22+
```ts filename="next.config.ts" switcher
2323
import type { NextConfig } from 'next'
2424

2525
const nextConfig: NextConfig = {
@@ -31,6 +31,17 @@ const nextConfig: NextConfig = {
3131
export default nextConfig
3232
```
3333

34+
```js filename="next.config.js" switcher
35+
/** @type {import('next').NextConfig} */
36+
const nextConfig = {
37+
experimental: {
38+
dynamicIO: true,
39+
},
40+
}
41+
42+
module.exports = nextConfig
43+
```
44+
3445
Then, you can use the `use cache` directive at the file, component, or function level:
3546

3647
```tsx
@@ -137,7 +148,7 @@ You can use `use cache` at the component level to cache any fetches or computati
137148

138149
The props are serialized and form part of the cache key, and the cache entry will be reused as long as the serialized props produce the same value in each instance.
139150

140-
```tsx filename="app/components/bookings.tsx" highlight={2}
151+
```tsx filename="app/components/bookings.tsx" highlight={2} switcher
141152
export async function Bookings({ type = 'haircut' }: BookingsProps) {
142153
'use cache'
143154
async function getBookingsData() {
@@ -152,7 +163,7 @@ interface BookingsProps {
152163
}
153164
```
154165

155-
```jsx filename="app/components/bookings.js" highlight={2}
166+
```jsx filename="app/components/bookings.js" highlight={2} switcher
156167
export async function Bookings({ type = 'haircut' }) {
157168
'use cache'
158169
async function getBookingsData() {
@@ -295,7 +306,11 @@ async function CachedComponent({ performUpdate }) {
295306
```tsx filename="app/ClientComponent.tsx" switcher
296307
'use client'
297308

298-
export default function ClientComponent({ action }) {
309+
export default function ClientComponent({
310+
action,
311+
}: {
312+
action: () => Promise<void>
313+
}) {
299314
return <button onClick={action}>Update</button>
300315
}
301316
```

0 commit comments

Comments
 (0)