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

121
Visualizações
In First render it shows "undefined" and in second render it shows "data" in React.js

My problem is that when I send Array of data as prop and console.log it in another component , it first shows "undefined" and then it shows the data. I get data from API and then send it as prop to another component. I already removed React.strictMode from index.js file but it still keeps happening.

for example :

const menu = [
{name : "firstFood"},{name:"Second Food"}
]

<MenuTable menu ={menu} />

and in other component I console.log it.

const MenuTable = (props)=>{
console.log(props.menu)
}

In first render it shows undefined then it shows data

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think you wrote:

 const [menu, setMenu] = useState()

Then you call the api and setMenu(response) with the data response. Therefore, menu, at first, is undefined. You should try useState([]), then the first render of menu is [].

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