react list render all components code example
Example 1: map function in react
function NameList() {
const names = ['Bruce', 'Clark', 'Diana']
return (
<div>
{names.map(name => <h2>{name}</h2>)}
</div>
)
}
Example 2: how to get element from arraylist react
function NonIdiomaticList(props) {
let array = [];
for(let i = 0; i < props.items.length; i++) {
array.push(
<Item key={i} item={props.items[i]} />
);
}
return (
<div>
{array}
</div>
);
}
Example 3: react create list of array in react
const App = props => { const quoteArray = props.quotes.map((quote) => { return ( <Quote text={quote.text} author={quote.author} /> ); }); return ( <div> <h2>Famous Quotes</h2> {quoteArray} </div> );};App.propTypes = { quotes: React.PropTypes.array}