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

533
Vistas
Problem while returning an array on react: Uncaught TypeError: Cannot read properties of undefined (reading 'items')

I am triying to return p in a div from an array that come from a useState hook, but give me this error:Uncaught TypeError: Cannot read properties of undefined (reading 'items')

Image

function App(){

        
    const [items, setLab] = useState(["a", "b", "c"])

    console.log(items)
    return (
        <div> laberinto
        {this.items.bind(this).map((item) => {
             <div>
                 <p>{item}</p> 
             </div>
         })
        }
        </div>
    )

}

 
render(
    <App/>,
    document.getElementById('app'),
);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Your App component is a functional component (not a class component), so you don't need to use this keyword.

{items.map((item) => {
  <div>
    <p>{item}</p>
  </div>
 })
}

More detailed about Functional and Class components here: https://reactjs.org/docs/components-and-props.html#function-and-class-components

about 4 years ago · Juan Pablo Isaza Denunciar

0

Issues

  1. this is simply undefined in React function components.
  2. Array.prototype.map callback needs to return a value being mapped to.

Solution

  • Remove any this references.
  • Return JSX from the .map callback. Don't forget to include the React keys.

Explicit return statement in the function body:

function App() {
  const [items, setLab] = useState(["a", "b", "c"]);

  return (
    <div>
      laberinto
      {items.map((item) => {
        return (
          <div key={item}>
            <p>{item}</p> 
          </div>
        );
      })}
    </div>
  );
}

Implicit return without a function body:

function App() {
  const [items, setLab] = useState(["a", "b", "c"]);

  return (
    <div>
      laberinto
      {items.map((item) => (
        <div key={item}>
          <p>{item}</p> 
        </div>
      ))}
    </div>
  );
}
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