Ich habe folgende Array:dynamische Rendering in React
const elements = [
{
title: "foo"
section: <div>Foo <button onClick={sayHello}>Greet</button></div>
},
{
title: "bar"
section: <div>Bar <button onClick={sayHello}>Greet</button></div>
}
];
Ich möchte die Komponente mit so etwas wie machen:
const someSections = this.state.elements.map((item, i) => (
<div key={i}>
{item.section}
</div>
));
...
render(){
return (
...
<div>
{someSections}
</div>
)
}
Aber ich kann sie nicht machen. Der Fehler ist:
Uncaught Error: objects are not valid as a React child
item.section, nicht link.section in Ihrer Karte: D – Kornflexx
Ihre Daten sollten wirklich nicht HTML enthalten, nur die Vorlagen –