如何在反应中使用.map渲染JSX数组

维克兰特·巴特

我有一个类似于以下对象的数组:


const features = [
{
        name: "Sponsor Block",
        images: [sponsorBlock1, sponsorBlock2],
        data: [
            `Uses the API found ${<a href='example.com/'>here</a>}. You can find more information on how it works`,
            "Lorem ipsum ........"
        ],
    },
]

在第一点中,您可以看到我正在使用模板字符串来注入JSX(我不确定这是否是正确的方法)

我想在features数组上进行映射(循环),并在其中显示带有anchor标签的第一个点,以及其他仅作为普通文本的文本点。

但是,当我遍历第一个对象中的数据键时,将其显示在我的JSX-> [Object] [Object]中

有什么办法可以解决这个问题,同时仍将其保留在数组中?

为什么不简单地使用一系列片段组件

data:[
    <>Uses the API found <a href='example.com/'>here</a>. You can find more information on how it works</>,
    <>Lorem ipsum ........</>
]

然后在渲染时执行:

return (
    <ul>
        {features.data.map((d,i)=><li key={i}>{d}</li>}
    </ul>
)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章