Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!