📅  最后修改于: 2022-03-11 14:59:36.557000             🧑  作者: Mango
Copyimport { documentToReactComponents } from '@contentful/rich-text-react-renderer';
import { BLOCKS } from '@contentful/rich-text-types';
// Create a bespoke renderOptions object to target BLOCKS.EMBEDDED_ENTRY (linked entries e.g. videoEmbed
// and BLOCKS.EMBEDDED_ASSET (linked assets e.g. images)
const renderOptions = {
renderNode: {
[BLOCKS.EMBEDDED_ENTRY]: (node, children) => {
if (node.data.target.sys.contentType.sys.id === 'videoEmbed') {
return (
);
}
},
[BLOCKS.EMBEDDED_ASSET]: (node, children) => {
// render the EMBEDDED_ASSET as you need
return (
);
},
},
};
export default function RichTextResponse({ richTextResponse }) {
return <>{documentToReactComponents(richTextResponse, renderOptions)}>;
}