1- import { type PortableTextComponents , PortableText } from '@portabletext/react'
1+ import { type PortableTextBlock , type PortableTextComponents , PortableText } from '@portabletext/react-latest '
22import { studioTheme , ThemeProvider } from '@sanity/ui'
3- import { StrictMode , useEffect , useState } from 'react'
3+ import { StrictMode , Suspense , use , useEffect , useState } from 'react'
44import { createRoot } from 'react-dom/client'
5+ import { createClient } from '@sanity/client'
56
67import { AnnotatedMap } from './components/AnnotatedMap'
78import { CharacterReference } from './components/CharacterReference'
@@ -12,7 +13,7 @@ import {LinkableHeader} from './components/LinkableHeader'
1213import { SchnauzerList } from './components/SchnauzerList'
1314import { hasSpeechApi , SpeechSynthesis } from './components/SpeechSynthesis'
1415import { TermDefinition } from './components/TermDefinition'
15- import { blocks } from './fixture'
16+ // import {blocks} from './fixture'
1617
1718/**
1819 * Note that these are statically defined (outside the scope of a function),
@@ -48,14 +49,21 @@ const ptComponents: PortableTextComponents = {
4849 } ,
4950}
5051
52+ const client = createClient ( { projectId : 'ppsg7ml5' , dataset : 'test' , apiVersion : '2025-12-09' , useCdn : true , perspective : 'published' } )
53+ const promise = client . fetch < PortableTextBlock [ ] > ( `*[_type == "simpleBlock" && _id == $id][0].body` , { id : '6468a09e-ce29-48d3-8b36-4b058366e6b5' } )
54+
5155function Demo ( ) {
56+ const blocks = use ( promise )
5257 const [ count , setCount ] = useState ( 0 )
5358 const showingEverything = count >= blocks . length
5459 const blocksToShow = showingEverything ? blocks : blocks . slice ( 0 , count )
5560 useEffect ( ( ) => {
56- if ( ! showingEverything ) {
57- setCount ( count + 1 )
61+ if ( showingEverything ) {
62+ // setCount(count + 100)
63+ return undefined
5864 }
65+ const raf = requestAnimationFrame ( ( ) => setCount ( count + 30 ) )
66+ return ( ) => cancelAnimationFrame ( raf )
5967 } , [ showingEverything , count ] )
6068 return < PortableText value = { blocksToShow } components = { ptComponents } />
6169}
@@ -64,7 +72,9 @@ const root = createRoot(document.getElementById('demo-root')!)
6472root . render (
6573 < StrictMode >
6674 < ThemeProvider theme = { studioTheme } >
67- < Demo />
75+ < Suspense fallback = { < div > Loading...</ div > } >
76+ < Demo />
77+ </ Suspense >
6878 </ ThemeProvider >
6979 </ StrictMode > ,
7080)
0 commit comments