next-sanity 5.5.1 → 5.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ The official [Sanity.io][sanity] toolkit for Next.js apps.
|
|
|
15
15
|
- [Table of contents](#table-of-contents)
|
|
16
16
|
- [Installation](#installation)
|
|
17
17
|
- [Common dependencies](#common-dependencies)
|
|
18
|
-
- [Peer dependencies for embedded Sanity
|
|
18
|
+
- [Peer dependencies for embedded Sanity Studio](#peer-dependencies-for-embedded-sanity-studio)
|
|
19
19
|
- [Usage](#usage)
|
|
20
20
|
- [Quick start](#quick-start)
|
|
21
21
|
- [App Router Components](#app-router-components)
|
|
@@ -40,7 +40,6 @@ The official [Sanity.io][sanity] toolkit for Next.js apps.
|
|
|
40
40
|
- [Studio Routes with Pages Router](#studio-routes-with-pages-router)
|
|
41
41
|
- [Lower level control with `StudioProvider` and `StudioLayout`](#lower-level-control-with-studioprovider-and-studiolayout)
|
|
42
42
|
- [Migration guides](#migration-guides)
|
|
43
|
-
- [Release new version](#release-new-version)
|
|
44
43
|
- [License](#license)
|
|
45
44
|
|
|
46
45
|
## Installation
|
|
@@ -120,7 +119,7 @@ const client = createClient({
|
|
|
120
119
|
To fetch data in a React Server Component using the [App Router][app-router]:
|
|
121
120
|
|
|
122
121
|
```tsx
|
|
123
|
-
// ./src/
|
|
122
|
+
// ./src/app/page.tsx
|
|
124
123
|
import {client} from '@/src/utils/sanity/client'
|
|
125
124
|
|
|
126
125
|
type Post = {
|
|
@@ -151,7 +150,7 @@ export async function PostIndex() {
|
|
|
151
150
|
If you're using the [Pages Router][pages-router], then you can do the following from a page component:
|
|
152
151
|
|
|
153
152
|
```tsx
|
|
154
|
-
// ./src/pages/
|
|
153
|
+
// ./src/pages/index.tsx
|
|
155
154
|
import {client} from '@/src/utils/sanity/client'
|
|
156
155
|
|
|
157
156
|
type Post = {
|
|
@@ -213,23 +212,38 @@ This toolkit includes the [`@sanity/client`][sanity-client] that fully supports
|
|
|
213
212
|
|
|
214
213
|
Time-based revalidation is best for less complex cases and where content updates don't need to be immediately available.
|
|
215
214
|
|
|
216
|
-
```
|
|
217
|
-
// ./src/
|
|
218
|
-
import {
|
|
215
|
+
```tsx
|
|
216
|
+
// ./src/app/home/layout.tsx
|
|
217
|
+
import { client } from '@/src/utils/sanity/client'
|
|
218
|
+
import { PageProps } from '@/src/app/(page)/Page.tsx'
|
|
219
219
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
type HomePageProps = {
|
|
221
|
+
_id: string
|
|
222
|
+
title?: string
|
|
223
|
+
navItems: PageProps[]
|
|
224
|
+
}
|
|
223
225
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
226
|
+
export async function HomeLayout({children}) {
|
|
227
|
+
const home = await client.fetch<HomePageProps>(`*[_id == "home"][0]{...,navItems[]->}`,
|
|
228
|
+
next: {
|
|
229
|
+
revalidate: 3600 // look for updates to revalidate cache every hour
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
<main>
|
|
235
|
+
<nav>
|
|
236
|
+
<span>{home?.title}</span>
|
|
237
|
+
<ul>
|
|
238
|
+
{home?.navItems.map(navItem => ({
|
|
239
|
+
<li key={navItem._id}><a href={navItem?.slug?.current}>{navItem?.title}</a></li>
|
|
240
|
+
}))}
|
|
241
|
+
</ul>
|
|
242
|
+
</nav>
|
|
243
|
+
{children}
|
|
244
|
+
</main>
|
|
245
|
+
)
|
|
246
|
+
}
|
|
233
247
|
```
|
|
234
248
|
|
|
235
249
|
### Tag-based revalidation webhook
|