zyklus zyklus - 2 months ago 9
Javascript Question

React: render() and multiple children

I have a map component that's out of my control that renders all of it's direct children:

<point />
<circle />
<circle />

Now I'm trying to write a component that returns multiple objects:

<circle />
<circle />

But as the map only renders direct children, I'm not sure how to get this to work. Help?


If I am not wrong, I guess this is what you are looking for.

function MyComponent (props) {
  const objs = props.objs;
  const listItems = objs.map((obj) =>
    < {obj} />
  return (
    <map>{listItems} </map>

const objs = ['circle', 'circle'];
  <MyComponent objs={objs} />, //pass children i.e.,objs as props to the MyComponent