Lists in ReactJS

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 
  • {cities}
  • ; }); ReactDOM.render(
      {names}
    , document.getElementById('app') ); export default App;

    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) =>  
    
  • {cities}
  • ); return (
      {names}
    ); } const cities = ['Jaipur', 'Jodhpur', 'Udaipur', 'Pune', 'Chandigarh']; ReactDOM.render( , document.getElementById('app') ); export default App;

    Output:

          ●	Jaipur
          ●	Jodhpur
          ●	Udaipur
          ●	Pune
          ●	Chandigarh