Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

97
Visualizações
Passing an object to a component as prop

I'm very green at react, and I'm trying to learn the library by messing around a bit.

I'm having problems passing an object to another component. Ive created an array of objects that holds 2 string variables, 1 function and 1 int.

I'm trying to populate this inside a Grid container(Material UI framework).

When I pass the object to the other react component, it arrives as undefined. Ive tried to check if I'm passing a valid object by logging it to the console first, and it is valid.

I've also tried to refer to the properties in the component that receives the object, but the browser console throws Uncaught TypeError: Cannot read properties of undefined (reading 'person').

Does anyone know why it is being sent as undefined?

PersonList.js:

const personListe = [
    {
        firstName:'testFirstname',
        lastName:'testLastName',
        getFullName:function()
        {
            return `${this.firstName} ${this.lastName}`
        },
        age:28
    }
]

export default function PersonList() {
    
  return (
      <>
        <Grid container spacing={3}>
            {personListe.map((person) => {
                 return(
                    <Grid item xs={3} key={person.firstName}>
                    <PersonCard person={person} />   
                    </Grid>
                )
            })}
        </Grid>
    </>
  );
}

PersonCard.js:

export default function PersonCard({props})
{
    return (<>
        {console.log(props)}
    </>)
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The PersonCard Component recieves props object which includes the person object inside it.

export default function PersonCard({person})
{
    return (
      <>
        {console.log(person)}
      </>
    )
}

OR

export default function PersonCard(props)
{
    return (
      <>
        {console.log(props.person)}
      </>
    )
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda