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

115
Vistas
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 Respuestas
Responde la pregunta

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 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