【问题标题】:Contentful rich text removing css class on adding new option在添加新选项时删除 css 类的内容丰富的文本
【发布时间】:2021-10-12 16:55:45
【问题描述】:

我在 Next.js 项目中使用 contentful

我遇到了内容丰富的富文本问题,当我添加一个新选项时,它会从我的第一个选项中删除 css 类并仅应用第二个选项。无法理解这是为什么。选项代码如下:

const options = {

renderNode: {
    [BLOCKS.PARAGRAPH]: (node, children) => {
        return (
            <p className="text-primary">{children}</p>
        )
    }
},
renderNode: {
    [BLOCKS.LIST_ITEM]: (node, children) => {
        return (
            <li className="text-sundown">{children}</li>
        )
    }
}

};

【问题讨论】:

    标签: javascript reactjs next.js contentful


    【解决方案1】:

    这是因为您不能在 options 中拥有多个 renderNode 属性。将段落和列表项 css 放在一个 renderNode 中。

    const options = {
    
    renderNode: {
        [BLOCKS.PARAGRAPH]: (node, children) => {
            return (
                <p className="text-primary">{children}</p>
            )
        },
        [BLOCKS.LIST_ITEM]: (node, children) => {
            return (
                <li className="text-sundown">{children}</li>
            )
        }
    };
    
    

    【讨论】:

    • 啊,愚蠢的错误。太感谢了。现在修复了:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 2021-11-14
    • 2022-08-07
    • 2017-10-23
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    相关资源
    最近更新 更多