Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

76
Vistas
List always returns undefined

I'm extremely new to ReactJS and I have no idea what I am doing wrong but my City list always comes back undefined. The number list renders just fine. I have been fighting this for the past 3 hours and I am just stumped.

Could someone please help me out?

I used the create-react-app and I have removed the React.StrictMode from the index.js file. Everything I am doing is in the App.js.

import logo from './logo.svg';
import './App.css';
import React from 'react';

console.clear();

//Simple List of numbers
let numbers = [1, 2, 3, 4, 5];
let numberList = numbers.map((number) =>
  <li key={number}>{number}</li>
);

//we would pull something from a db and pass it to the function
let cities = ['Boise', 'Nampa', 'Meridian', 'Caldwell'];
let Cities = (arrayList) => {
  
  let cities = arrayList.cities;
  console.log(cities);
  let cityList = cities.map((item, index) =>{
    <li key={index}>{item}</li>
  });
  console.log(cityList);
  return(
    <ul>{cityList}</ul>
  );

  /*
  return(
    <ul>
      {
        //You cannot use a forEach it will always return undefined. ReactJS needs a key so we can use the index of the item
        cities.map((item, index) =>{
          <li key={index}>{item}</li>
        })
      }
    </ul>
  );
  */

};

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <h2>It is {new Date().toLocaleTimeString()}</h2>
        <div>
          <h2>Numbers</h2>
          <ul>{numberList}</ul>
        </div>
        <div>
          <h2>Cities</h2>
          <Cities cities={cities}/>
        </div>
      </header>
    </div>
  );
}

export default App;

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have curly brackets, which means this is a function and you need to return something. e.g. return <li .... More likely, you intended the curly brackets to be parentheses.

let cityList = cities.map((item, index) =>{
    <li key={index}>{item}</li>
});

You want one of these:

let cityList = cities.map((item, index) =>{
    return <li key={index}>{item}</li>
});

let cityList = cities.map((item, index) => (
    <li key={index}>{item}</li>
));
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda