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

122
Vistas
loading data asynchronously with multipe Axios calls

I have a bunch of charts to display and need to load data separately for each of them.

The data structure identifying each chart is array and looks like this (subarray can host one or more charts. In case of multiple items in subarray, the chart will have multiple axis):

"charts":[["chart1"], ["chart2", "chart4", ...], ...]

There is not known in advance how many items will be in the array and how much they will have subitems.

My approach

First I go through charts and display placeholders (loaders), then if data state is available, display the chart:

const[data, setData] = useState(null);

return(
  charts.map(item => {
     (item in data && data[item] !== "") ? <Chart data={data[item]} /> : <Loader />
  })
)

For the Axios data fetch I thought to use useEffect which would fill the data state variable, which would then re-render the component to show already loaded charts.

My issue here is, that I am not sure how to utilise useEffect to do this as calling Axios in a loop and setting data state variable in a loop does not seem right to me. I guess it would then create infinite loop.

The other a bit smaller question is, how to wait for data load of all subitems to display multiaxis chart, if it applies.

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

0

Based off the comments, here is an example of updating setData in a useEffect hook with the responses from multiple api calls to different endpoints:

const [data, setData] = useState([])

useEffect(() => {
  const getData = async(url) => {
    const res = await axios.get(url)
    setData(prevState => [...prevState, res.data])
  }
  getData(url1)
  getData(url2)
  getData(url3)
}, [])
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