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

188
Vistas
I can't access the data stored in my sessionDates array in my DateList function

I can't access the data stored in my sessionDates array in my DateList function

this is the code from my index.js including the api call

import React from "react";
import ReactDOM from "react-dom";
const availableDates = [];
const available = [];
const sessionDates = [];

function getDates(e){
  getDate(apiUrl);
}

const getDate = async (apiUrl)=>{
  const res = await fetch(apiUrl)
  try {
    const data = await res.json();
    availableDates.push(data);
    availableDates.map((datee) => {
      datee.map((session) => {
        sessionDates.push(session.date.slice(0, 10));
      });
    });
    return sessionDates;
  }  catch(error) {
    console.log("error", error);
  }
}
window.addEventListener('load', getDates);

function DateList(){
  return <section>{sessionDates[0]}</section>;
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

While you are setting sessionDates based on the api call, there is nothing in your code that prompts DateList to re-render when sessionDates changes. As such, it will only display the initial value of sessionDates, for which sessionDates[0] is undefined.

Instead, I recommend that you use the useEffect hook to trigger your api call and implement sessionDates using useState.

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