I wanted to fetch data from contentful and I used rich text data type with embedded-entry-block. But I always get the undefined when I tried to call [name of field].data.target.fields from the object. Can someone explain what should I do?
Hi Shafira,
Unfortunately you can’t access the embedded-entry’s fields directly. But you will need to use a Rich Text renderer, like this one:
You can see in the example (JS) code:
const options = {
renderNode: {
[BLOCKS.EMBEDDED_ENTRY]: (node) => {
const { title, description } = node.data.target.fields;
return <CustomComponent title={title} description={description} />
}
}
};
That the nodes need to be selected and then can be accessed. I know it’s a little tricky, but I hope this can point you in the right direction. We have also rich text parsers for other languages, as you can find here:
https://www.contentful.com/developers/docs/tutorials/general/getting-started-with-rich-text-field-type/#get-started-with-various-platforms
Thank you for the answer! I’ll try using Rich Text renderer as you said