React Lists
To display data in an ordered format, lists are used in React JS, much similar to the lists in JavaScript. In ReactJs, the map() function is used for traversing the lists.
Example:
import React from 'react'; import ReactDOM from 'react-dom'; const cities = ['Jaipur', 'Jodhpur', 'Udaipur', 'Pune', 'Chandigarh']; const names = cities.map((cities)=>{ return
- {names}
Output:
● Jaipur ● Jodhpur ● Udaipur ● Pune ● Chandigarh
Rendering Lists inside components Example:
import React from 'react'; import ReactDOM from 'react-dom'; function CityList(props) { const cities = props.cities; const names = cities.map((cities) =>
- {names}
Output:
● Jaipur ● Jodhpur ● Udaipur ● Pune ● Chandigarh