Skip to content

Commit 1e14927

Browse files
authored
chore: update sdk version (#28)
* chore: updated SDK packages & implementations * fix: fix hook names in examples * chore: make it RC
1 parent 22535db commit 1e14927

File tree

7 files changed

+84
-81
lines changed

7 files changed

+84
-81
lines changed

apps/sdk-explorer/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"@sanity/color": "^3.0.6",
1515
"@sanity/icons": "^3.5.7",
1616
"@sanity/logos": "^2.1.13",
17-
"@sanity/sdk": "0.0.0-alpha.18",
18-
"@sanity/sdk-react": "0.0.0-alpha.19",
17+
"@sanity/sdk": "^0.0.0-rc",
18+
"@sanity/sdk-react": "^0.0.0-rc",
1919
"@sanity/types": "^3.72.1",
2020
"@sanity/ui": "^2.11.4",
2121
"@tailwindcss/vite": "^4.0.0",

apps/sdk-explorer/src/Home.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ export default function Home(): JSX.Element {
4646
to="/document-collections/document-table"
4747
title="Document table"
4848
description="A tabular rendering of documents and their content"
49-
hooks={['usePaginatedList', 'useProjection']}
49+
hooks={['usePaginatedDocuments', 'useProjection']}
5050
styling="Tailwind"
5151
img={DocumentTableImage}
5252
/>
5353
<ExampleCard
5454
to="/document-collections/preview-list"
5555
title="Preview list"
5656
description="A list of document previews"
57-
hooks={['useInfiniteList', 'useProjection']}
57+
hooks={['useDocuments', 'useProjection']}
5858
styling="Sanity UI"
5959
img={PreviewListImage}
6060
/>
6161
<ExampleCard
6262
to="/document-collections/preview-grid"
6363
title="Preview grid"
6464
description="A grid of document previews"
65-
hooks={['useInfiniteList', 'useProjection']}
65+
hooks={['useDocuments', 'useProjection']}
6666
styling="Tailwind"
6767
img={PreviewGridImage}
6868
/>

apps/sdk-explorer/src/document-collections/DocumentTable/DocumentTable.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import './styles.css'
22

3-
import {DocumentHandle, usePaginatedList, useProjection} from '@sanity/sdk-react'
3+
import {DocumentHandle, usePaginatedDocuments, useProjection} from '@sanity/sdk-react'
44
import {type JSX, useRef} from 'react'
55

66
import ExampleLayout from '../../ExampleLayout'
77

88
interface MovieProjectionResults {
9-
results: {
9+
data: {
1010
title: string
1111
posterImage: string
1212
cast: string
@@ -19,9 +19,9 @@ function DocumentRow({document}: {document: DocumentHandle}) {
1919
const ref = useRef(null)
2020

2121
const {
22-
results: {title, posterImage, cast, popularity, releaseDate},
22+
data: {title, posterImage, cast, popularity, releaseDate},
2323
}: MovieProjectionResults = useProjection({
24-
document,
24+
...document,
2525
ref,
2626
// In our projection, we will:
2727
// 1. Get the title of the movie
@@ -53,7 +53,7 @@ function DocumentRow({document}: {document: DocumentHandle}) {
5353

5454
export default function DocumentTable(): JSX.Element {
5555
const {data, currentPage, totalPages, nextPage, previousPage, hasNextPage, hasPreviousPage} =
56-
usePaginatedList({
56+
usePaginatedDocuments({
5757
filter: '_type == "movie"',
5858
pageSize: 6,
5959
orderings: [{field: 'releaseDate', direction: 'desc'}],
@@ -63,9 +63,9 @@ export default function DocumentTable(): JSX.Element {
6363
<ExampleLayout
6464
title="Document table"
6565
codeUrl="https://github.com/sanity-io/sdk-examples/blob/main/apps/sdk-explorer/src/document-collections/DocumentTable/DocumentTable.tsx"
66-
hooks={['usePaginatedList', 'useProjection']}
66+
hooks={['usePaginatedDocuments', 'useProjection']}
6767
styling="Tailwind"
68-
summary="This example uses the usePaginatedList hook to retrieve a paginated collection of documents with six items per page, in addition to state and functions to control the pagination. The useProjection hook is used to retrieve contents and create projections from each document. Each document and its content and projections are then rendered in a table row."
68+
summary="This example uses the usePaginatedDocuments hook to retrieve a paginated collection of documents with six items per page, in addition to state and functions to control the pagination. The useProjection hook is used to retrieve contents and create projections from each document. Each document and its content and projections are then rendered in a table row."
6969
>
7070
<table className="w-full text-sm border-collapse">
7171
<thead>
@@ -89,7 +89,7 @@ export default function DocumentTable(): JSX.Element {
8989
</thead>
9090
<tbody>
9191
{data.map((document) => (
92-
<DocumentRow key={document._id} document={document} />
92+
<DocumentRow key={document.documentId} document={document} />
9393
))}
9494
</tbody>
9595
</table>

apps/sdk-explorer/src/document-collections/PreviewGrid/PreviewGrid.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import './styles.css'
22

33
import {DocumentHandle} from '@sanity/sdk'
4-
import {useInfiniteList, useProjection} from '@sanity/sdk-react'
4+
import {useDocuments, useProjection} from '@sanity/sdk-react'
55
import {Spinner} from '@sanity/ui'
66
import {type JSX, Suspense, useRef} from 'react'
77

88
import ExampleLayout from '../../ExampleLayout'
99

1010
// @todo replace with type from SDK
1111
interface ProjectionResults {
12-
results: {
12+
data: {
1313
title: string
1414
cast: string
1515
posterImage: string
1616
}
17-
isPending: boolean
1817
}
1918

2019
// The DocumentPreview component uses the `usePreview` hook to render a document preview interface
@@ -26,9 +25,9 @@ function DocumentPreview({document}: {document: DocumentHandle}): JSX.Element {
2625
// Project the title, first 2 cast members, and poster image values for the document,
2726
// plus an `isPending` flag to indicate if projection value resolutions are pending
2827
const {
29-
results: {title, cast, posterImage},
28+
data: {title, cast, posterImage},
3029
}: ProjectionResults = useProjection({
31-
document,
30+
...document,
3231
ref,
3332
projection: `{
3433
title,
@@ -69,7 +68,7 @@ function DocumentPreview({document}: {document: DocumentHandle}): JSX.Element {
6968
function PreviewGrid(): JSX.Element {
7069
// Use the `useDocuments` hook to return an index of document handles for all of our 'movie' type documents
7170
// Sort the documents by the release date
72-
const {data: movies} = useInfiniteList({
71+
const {data: movies} = useDocuments({
7372
filter: '_type == "movie"',
7473
orderings: [{field: 'releaseDate', direction: 'desc'}],
7574
})
@@ -78,14 +77,14 @@ function PreviewGrid(): JSX.Element {
7877
<ExampleLayout
7978
title="Preview grid"
8079
codeUrl="https://github.com/sanity-io/sdk-examples/blob/main/apps/sdk-explorer/src/document-collections/PreviewGrid/PreviewGrid.tsx"
81-
hooks={['useInfiniteList', 'useProjection']}
80+
hooks={['useDocuments', 'useProjection']}
8281
styling="Tailwind"
83-
summary="This example uses the useInfiniteList hook to retrieve a collection of documents. That collection is then mapped over, with each document passed to a component that uses the useProjection hook to retrieve each document’s title and poster image, and to create a projection of the first three listed cast members. The results are displayed in a grid."
82+
summary="This example uses the useDocuments hook to retrieve a collection of documents. That collection is then mapped over, with each document passed to a component that uses the useProjection hook to retrieve each document’s title and poster image, and to create a projection of the first three listed cast members. The results are displayed in a grid."
8483
>
8584
<div className="grid grid-cols-1 gap-x-4 gap-y-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
8685
{movies.map((movie) => (
87-
<Suspense key={movie._id} fallback={<Spinner />}>
88-
<DocumentPreview key={movie._id} document={movie} />
86+
<Suspense key={movie.documentId} fallback={<Spinner />}>
87+
<DocumentPreview document={movie} />
8988
</Suspense>
9089
))}
9190
</div>

apps/sdk-explorer/src/document-collections/PreviewList/PreviewList.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {DocumentHandle} from '@sanity/sdk'
2-
import {useInfiniteList, useProjection} from '@sanity/sdk-react'
2+
import {useDocuments, useProjection} from '@sanity/sdk-react'
33
import {Button, Card, Flex, Inline, Spinner, Stack, Text} from '@sanity/ui'
44
import {type JSX, Suspense, useRef} from 'react'
55

@@ -17,12 +17,11 @@ function Loading() {
1717

1818
// @todo replace with type from SDK
1919
interface ProjectionResults {
20-
results: {
20+
data: {
2121
title: string
2222
cast: string
2323
posterImage: string
2424
}
25-
isPending: boolean
2625
}
2726

2827
// The DocumentPreview component uses the `usePreview` hook to render a document preview interface
@@ -34,9 +33,9 @@ function DocumentPreview({document}: {document: DocumentHandle}) {
3433
// Project the title, first 3 cast mambers, and post image values for the document,
3534
// plus an `isPending` flag to indicate if projection value resolutions are pending
3635
const {
37-
results: {title, cast, posterImage},
36+
data: {title, cast, posterImage},
3837
}: ProjectionResults = useProjection({
39-
document,
38+
...document,
4039
ref,
4140
projection: `{
4241
title,
@@ -70,31 +69,23 @@ function DocumentPreview({document}: {document: DocumentHandle}) {
7069
function PreviewList(): JSX.Element {
7170
// Use the `useDocuments` hook to return an index of document handles for all of our 'movie' type documents
7271
// Sort the documents by the the release date
73-
const {data: movies, isPending} = useInfiniteList({
72+
const {data: movies} = useDocuments({
7473
filter: '_type == "movie"',
7574
orderings: [{field: 'releaseDate', direction: 'desc'}],
7675
})
7776

78-
if (isPending) {
79-
return (
80-
<Flex align="center" justify="center" padding={5}>
81-
<Spinner />
82-
</Flex>
83-
)
84-
}
85-
8677
return (
8778
<ExampleLayout
8879
title="Preview list"
8980
codeUrl="https://github.com/sanity-io/sdk-examples/blob/main/apps/sdk-explorer/src/document-collections/PreviewList/PreviewList.tsx"
90-
hooks={['useInfiniteList', 'useProjection']}
81+
hooks={['useDocuments', 'useProjection']}
9182
styling="Sanity UI"
92-
summary="This example uses the useInfiniteList hook to retrieve a collection of documents. That collection is then mapped over, with each document passed to a component that uses the useProjection hook to retrieve each document’s title and poster image, and to create a projection of the first three listed cast members."
83+
summary="This example uses the useDocuments hook to retrieve a collection of documents. That collection is then mapped over, with each document passed to a component that uses the useProjection hook to retrieve each document’s title and poster image, and to create a projection of the first three listed cast members."
9384
>
9485
<Stack>
9586
{movies.map((movie) => (
96-
<Suspense key={movie._id} fallback={<Loading />}>
97-
<DocumentPreview key={movie._id} document={movie} />
87+
<Suspense key={movie.documentId} fallback={<Loading />}>
88+
<DocumentPreview document={movie} />
9889
</Suspense>
9990
))}
10091
</Stack>

apps/sdk-explorer/src/main.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import './inter.css'
22

3-
import {createSanityInstance} from '@sanity/sdk'
4-
import {SanityProvider} from '@sanity/sdk-react'
3+
import {SanityApp} from '@sanity/sdk-react'
54
import {Flex, Spinner, ThemeProvider} from '@sanity/ui'
65
import {buildTheme} from '@sanity/ui/theme'
76
import {StrictMode, Suspense} from 'react'
@@ -12,10 +11,10 @@ import App from './App.tsx'
1211

1312
const theme = buildTheme()
1413

15-
const sanityInstance = createSanityInstance({
14+
const sanityConfig = {
1615
projectId: 'v28v5k8m',
1716
dataset: 'production',
18-
})
17+
}
1918

2019
const GlobalStyle = createGlobalStyle`
2120
body {
@@ -36,9 +35,9 @@ createRoot(document.getElementById('root')!).render(
3635
<GlobalStyle />
3736
<ThemeProvider theme={theme}>
3837
<Suspense fallback={<Loading />}>
39-
<SanityProvider sanityInstances={[sanityInstance]}>
38+
<SanityApp config={[sanityConfig]} fallback={<Loading />}>
4039
<App />
41-
</SanityProvider>
40+
</SanityApp>
4241
</Suspense>
4342
</ThemeProvider>
4443
</StrictMode>,

0 commit comments

Comments
 (0)