#useSWR API call returning 'undefined'
26 messages · Page 1 of 1 (latest)
nextJS is returning:
XHR failed loading: GET "https://app.domain.com/api/records/"
I'm just showing what the data looks like that I'm trying to return
Are you setting any headers in your request?
I switched the domain to a public random generator API and it works, I guess something is wrong with my API data
both have content-type: application/json so I'm not even sure.
It may be a cors issue. Try making a request to it with Postman and see if it works
doing now, would I have to setup CORS on the api server or nextjs?
what's weird is that I'm using getStaticProps to pull data from the same API endpoint.
on another page and it works just fine
getStaticProps runs on the server.
CORS is a browser-thing.
Yeah i just realized that the same endpoint im using on getStaticProps is not working with the SWR
looking into cors now..thanks all
enabled CORS still getting undefined.
what's shown in your network tab?
i dont get it, nextJS is hitting the endpoint
console is saying "XHR finished loading: GET" though
are you using the async fetchData function? I think it probably should be async
I would use async/await for everything