0

I created a Next.JS API which extracts data from a CSV file and returns the data, which works fine.

res.status(200).json(upCommingDates);

which returns the following when accessing it:

["2022-12-11T23:00:00.000Z","2023-11-26T23:00:00.000Z"]

The following code snipped should get the data and return the values.

const fetcher = (url) => fetch(url).then((res) => res.json());
 
function getMatchData() {
    const { nextMatchData, nextMatchError } = useSWR('/api/parsenextmatch', fetcher);

    if (nextMatchError) return "Error...";
    if (!nextMatchData) return "Loading...";
    
    console.log(nextMatchData);
    
    return nextMatchData;
};

Unfortunatly nextMatchData = 'undefined'. The joke is that this worked this morning, but I did alot of changes to the code, but no commit.

I was rewriting the code so many times, that I can not recap all. Assistance for where to look at would be very appriciated already.

pawl133
  • 3
  • 2
  • 1
    You should use `const { data, error } = useSWR('/api/parsenextmatch', fetcher);` instead. If you want to rename `data`/`error` then use `const { data: nextMatchData, error: nextMatchError }`. – juliomalves Nov 12 '22 at 15:55

0 Answers0