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.
Files changed (2) hide show
  1. package/README.md +33 -19
  2. 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 Sudio](#peer-dependencies-for-embedded-sanity-sudio)
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/components/PostIndex.tsx
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/Index.tsx
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
- ```ts
217
- // ./src/utils/sanity/client.ts
218
- import {createClient} from 'next-sanity'
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
- const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID // "pv8y60vp"
221
- const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET // "production"
222
- const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION || '2023-05-03'
220
+ type HomePageProps = {
221
+ _id: string
222
+ title?: string
223
+ navItems: PageProps[]
224
+ }
223
225
 
224
- const client = createClient({
225
- projectId,
226
- dataset,
227
- apiVersion, // https://www.sanity.io/docs/api-versioning
228
- useCdn: true, // if you're using ISR or only static generation at build time then you can set this to `false` to guarantee no stale content
229
- next: {
230
- revalidate: 3600, // look for updates to revalidate cache every hour
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-sanity",
3
- "version": "5.5.1",
3
+ "version": "5.5.2",
4
4
  "description": "Sanity.io toolkit for Next.js",
5
5
  "keywords": [
6
6
  "sanity",