Unverified Commit a26a753f authored by Joseph's avatar Joseph Committed by GitHub

docs: fix snippets in getting started (#83228)

Fixing snippets in Getting Started
parent 4996d9fb
......@@ -154,7 +154,7 @@ export default function Counter() {
}
```
```jsx filename="app/ui/counter.tsx" highlight={1} switcher
```jsx filename="app/ui/counter.js" highlight={1} switcher
'use client'
import { useState } from 'react'
......
......@@ -60,7 +60,7 @@ See the [`fetch` API reference](/docs/app/api-reference/functions/fetch) to lear
`unstable_cache` allows you to cache the result of database queries and other async functions. To use it, wrap `unstable_cache` around the function. For example:
```tsx filename="app/lib/data.ts swichter
```ts filename="app/lib/data.ts" switcher
import { db } from '@/lib/db'
export async function getUserById(id: string) {
return db
......@@ -103,11 +103,11 @@ export default async function Page({
}
```
```jsx filename="app/page.jsx" highlight={2,7,9} switcher
import { unstable_cache } from 'next/cache';
import { getUserById } from '@/app/lib/data';
```jsx filename="app/page.js" highlight={2,7,9} switcher
import { unstable_cache } from 'next/cache'
import { getUserById } from '@/app/lib/data'
export default async function Page({ params } }) {
export default async function Page({ params }) {
const { userId } = await params
const getCachedUser = unstable_cache(
......@@ -115,7 +115,7 @@ export default async function Page({ params } }) {
return getUserById(userId)
},
[userId] // add the user ID to the cache key
);
)
}
```
......
......@@ -54,7 +54,7 @@ export const metadata: Metadata = {
export default function Page() {}
```
```jsx filename="app/blog/layout.tsx" switcher
```jsx filename="app/blog/layout.js" switcher
export const metadata = {
title: 'My Blog',
description: '...',
......@@ -127,7 +127,7 @@ Learn more about [streaming metadata](/docs/app/api-reference/functions/generate
There may be cases where you need to fetch the **same** data for metadata and the page itself. To avoid duplicate requests, you can use React's [`cache` function](https://react.dev/reference/react/cache) to memoize the return value and only fetch the data once. For example, to fetch the blog post information for both the metadata and the page:
```tsx filename="app/lib/data.ts" highlight={5} switcher
```ts filename="app/lib/data.ts" highlight={5} switcher
import { cache } from 'react'
import { db } from '@/app/lib/db'
......@@ -138,7 +138,7 @@ export const getPost = cache(async (slug: string) => {
})
```
```jsx filename="app/lib/data.js" highlight={5} switcher
```js filename="app/lib/data.js" highlight={5} switcher
import { cache } from 'react'
import { db } from '@/app/lib/db'
......@@ -242,9 +242,9 @@ The more specific image will take precedence over any OG images above it in the
The [`ImageResponse` constructor](/docs/app/api-reference/functions/image-response) allows you to generate dynamic images using JSX and CSS. This is useful for OG images that depend on data.
For example, to generate a unique OG image for each blog post, add a `opengraph-image.ts` file inside the `blog` folder, and import the `ImageResponse` constructor from `next/og`:
For example, to generate a unique OG image for each blog post, add a `opengraph-image.tsx` file inside the `blog` folder, and import the `ImageResponse` constructor from `next/og`:
```tsx filename="app/blog/[slug]/opengraph-image.ts" switcher
```tsx filename="app/blog/[slug]/opengraph-image.tsx" switcher
import { ImageResponse } from 'next/og'
import { getPost } from '@/app/lib/data'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment