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

156
Vistas
is there any way to usestate respond immediately?

I was wanting to get value from the my server of the node with the usestate, but it returns the empty array value first and then pops up the value of my axios

has any way of the value of the axios appears first than that of the empty array ?

my code:

const [valTop, valTopstate] = useState([])

    async function MusicTop() {
        axios("http://localhost:3001/")
        .then(res=>{
            valTopstate(res.data.tracks.data)
        })
    }
    
    useEffect(()=>{
        MusicTop()

    }, [valTop])

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your code is fine but UseEffect is executed only after the component is rendered, so you can apply a logic that is the array is empty then show the loader and if not show the array values, and if this is your child component what you can do is that when this child component is going to be executed then you can first fetch the required array value by calling a function in the parent component and pass the values as props in the child component.

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