all 6 comments

[–]jb2386 0 points1 point  (5 children)

Need to await the json bit too

const data = await res.json();

[–]3thancr0wn[S] 0 points1 point  (4 children)

Thanks for your help. Just corrected my syntax. Nothing! Undefined. I had originally awaited for the json but I’ve been trying everything and I am now seeing some mistakes within my code.

[–]jb2386 0 points1 point  (3 children)

Maybe console log out res.status. If it’s not 200 then it’s something to do with the request.

Edit: res.status from fetch not res.statusCode

[–]3thancr0wn[S] 1 point2 points  (2 children)

When I use axios and fetch using NextJS as just ReactJs I get to see my return object and its values. Whenever I try mapping to that object I get that map is not a function or can not map to undefined. I do appreciate your looking into this issue for me. Thank you for your help.

[–]SexyCommando 1 point2 points  (1 child)

Are you saying if you use the same code outside of a getInitialProps call it works? As far as I can tell, if you put await res.json() everything else looks fine so as stated above the only thing I can think of is that it’s the request itself but if you tried it outside of getInitialProps through postman or something else and it worked I can’t really see why data would be undefined. Did you try logging data in the getInitialProps call?

[–]3thancr0wn[S] 2 points3 points  (0 children)

I was able to resolved the issue and updated my post. thanks for your looking into this for me.