Skip to content

How to render fields.document return #322

Answered by simonswiss
NeeshSamsi asked this question in Q&A
Discussion options

You must be logged in to vote

Hey!

  1. It sort of was the best way to do it, but there is a "new" reader API option called resolvedLinkedFiles that you can pass to the reader call, and it will resolve the fields returned as Promises for you:
const homepage = await reader.singletons.homepage.read({ resolvedLinkedFiles: true })
  1. Yep, you can use the DocumentRenderer from Keystatic, which is designed to do exactly that — parse the structured JSON data into markup:
import { DocumentRenderer } from '@keystatic/core/renderer'

const homepage = await reader.singletons.homepage.read({ resolvedLinkedFiles: true })

return (
  <div>
    <h1>{post.title}</h1>
    <div>
      <DocumentRenderer document={homepage.storyDescription} />

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@NeeshSamsi
Comment options

@simonswiss
Comment options

Answer selected by NeeshSamsi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants