Render Custom Component Blocks With The DocumentRenderer In Keystatic

Share this video with your friends

Social Share Links

Send Tweet
Published a year ago
Updated 2 months ago

In this video, you'll render the custom YouTube video block with Keystatic's DocumentRenderer.

[00:00] So we have a YouTube video custom component block inside our first post, but if we visit the first post on the front end, it's not displaying. You can see the paragraph before and the paragraph after the custom video block, but this thing here is not being rendered. Let's take a look at our post page. So app site [00:20] slug page dot tsx. And if I scroll down, you'll see that our post is rendered with the document renderer. We're passing our content to this document renderer, but before any custom component blocks show anything, we need to define them in the component blocks prop for the document renderer. So this is an object. And for [00:40] each component block, we'll need a key that matches the component block name in the key static config. In our key static config file, we created the YouTube video component block, and therefore, we'll need a YouTube video key right here. So we want to render our showcase YouTube [00:59] video component. And thanks to the types we've set up, it tells us that we need a video ID prop. So let's add it. And we'll need here to receive that prop of YouTube video ID. So let's accept the props here, and we should be able to pass props dot YouTube video ID. So because [01:19] we've defined this YouTube video component block, now when the document renderer sees this YouTube video custom component, it'll know what to render because we've defined it here. And as a result, now our front end should show the video. And, yep, there it is. You can see it between the paragraph before and the paragraph after.

egghead
egghead

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today