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

308
Vistas
Uncaught TypeError: Cannot read properties of undefined (reading 'map') & React Props Rules

Summary of the Problem

  • Consider a search bar <SearchBar/> (where you type different college majors) and a dropdown <Dropdown/> (a dropdown showing some details about a major i.e. "About Computer Science > Professors of Computer Science", "Computer Science Ratings > Best Computer Science Calsses", etc). I enter a word into the search bar, then I click submit. The information on the dropdown should change depending on what the user submits. The information that goes in the dropdown is fetched from a mongo collection

  • Inside a React component, I have the following function. This function is called when the user clicks submit.

  • I expect the major variable to be updated once the above function is called (i.e. when the user clicks submit)

  • The dropdown is returned as <Dropdown dropdown_information={major.informationPiece1}/>, where major.informationPieces1 is a list of objects

  • The Dropdown component definition looks like:

const Dropdown = ({informationPieces1}) => {


  return (
    <>
        <ul>
            {informationPiece1.map((piece, index) => {
                
                return (
                   <h1 key={index}> {piece.name} <h1/>
                )
            })}
            
        </ul>
    </>
  )
}
  • However, it seems that informationPiece1 in informationPiece1.map((piece, index) => ... comes up as undefined. I get Uncaught TypeError: Cannot read properties of undefined (reading 'map')
  • However, if I console.log(informationPieces1) inside the Dropdown React component defintion, I see the array in the console properly.

I believe this is a React problem. I believe this may be related to an incorrect use of React's props on my part. What steps would you recommend me to follow to verify if this is true?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

You are calling Dropdown component with dropdown_information as prop and expecting informationPieces1 in the component. So or you call the component with the prop informationPieces1 or you use the prop dropdown_information inside the component

I'll clarify:

const Dropdown = ({informationPieces1}) => { // if you define the component like this the you must call it:

<Dropdown informationPieces1={}/>


///////////////////////////

// If you call the component like this:
<Dropdown dropdown_information={}/>

//then you must write the definition as:
const Dropdown = ({dropdown_information}) => {

Your prop's names must match in both the definition and the call

about 4 years ago · Santiago Gelvez 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