How to render fields.document return #322
Answered
by
simonswiss
NeeshSamsi
asked this question in
Q&A
-
Hey! So I am storing some data in the document field type. It returns an async function so I am receiving as follows: const homepage = await reader.singletons.homepage.read()
const story = await homepage?.storyDescription() Returns an array of document elements.
Returned data JSON.stringify(ied)[
{
"type": "paragraph",
"children": [
{
"text": "Education is a process of Exploration, Discovery, Application, Integration."
}
]
},
{
"type": "paragraph",
"children": [
{
"text": "It is a continuous journey to the source of knowledge itself. Through this process we help children and youngsters learn about not only academics but also the mind, emotions, relationships, work, money, health and critical thinking for a joyful and meaningful life."
}
]
},
{
"type": "paragraph",
"children": [
{
"text": "We Aim to help local students and youth to:"
}
]
},
{
"type": "ordered-list",
"children": [
{
"type": "list-item",
"children": [
{
"type": "list-item-content",
"children": [
{
"text": "Become educated and well-rounded individuals."
}
]
}
]
},
{
"type": "list-item",
"children": [
{
"type": "list-item-content",
"children": [
{
"text": "Become intellectually and emotionally independant and resilient individuals."
}
]
}
]
},
{
"type": "list-item",
"children": [
{
"type": "list-item-content",
"children": [
{
"text": "Become skilled and confident to take care of their lives and livelihoods."
}
]
}
]
},
{
"type": "list-item",
"children": [
{
"type": "list-item-content",
"children": [
{
"text": "Become aware, conscious and constructive members of the communities they live in."
}
]
}
]
}
]
},
{
"type": "paragraph",
"children": [
{
"text": ""
}
]
}
] |
Beta Was this translation helpful? Give feedback.
Answered by
simonswiss
Jun 16, 2023
Replies: 1 comment 2 replies
-
Hey!
const homepage = await reader.singletons.homepage.read({ resolvedLinkedFiles: true })
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} />
</div>
</div>
) This desperately needs documentation and exampes — but at least for now you can get a good amount of help from TypeScript. You can also reference to the Keystone Document Renderer here: https://keystonejs.com/docs/guides/document-fields#rendering Hope it helps! ✨ |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
NeeshSamsi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey!
resolvedLinkedFiles
that you can pass to the reader call, and it will resolve the fields returned as Promises for you:DocumentRenderer
from Keystatic, which is designed to do exactly that — parse the structured JSON data into markup: