0
我有以下阵列:动态渲染阵营
const elements = [
{
title: "foo"
section: <div>Foo <button onClick={sayHello}>Greet</button></div>
},
{
title: "bar"
section: <div>Bar <button onClick={sayHello}>Greet</button></div>
}
];
我想要的东西,如呈现组件:
const someSections = this.state.elements.map((item, i) => (
<div key={i}>
{item.section}
</div>
));
...
render(){
return (
...
<div>
{someSections}
</div>
)
}
但我不能使它们。错误是:
Uncaught Error: objects are not valid as a React child
item.section,而不是在你的地图link.section:d – Kornflexx
你的数据真的不应该包含HTML,只有模板 –