K
K
Konstantin Bozhkov2017-04-17 21:18:12
React
Konstantin Bozhkov, 2017-04-17 21:18:12

Iterating and passing elements through an attribute to a component?

It is necessary to iterate over the array returning the values ​​in jsx format and then passing them to the attribute of the component. Working example:

<ul>
  {this.props.productsInBasket.map((product) => <li key={product.name}>{product.name}</li>)}
</ul>

Required view:
wrappers.map(function(el){
  return <Wrapper element={el} childern={el.require.map((child) => <li>{child.name}</li>)}/>
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ildar Gizetdinov, 2017-04-17
@ybiks

wrappers.map(function(el){
  	return (
  		<Wrapper element={el}>
      {el.require.map((child, key) => {
        return <li key={key}>{child.name}</li>
      })}
    <Wrapper/>
  );
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question