zyklus zyklus - 1 year ago 93
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?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download