Next.js Discord

Discord Forum

Why is the response of string type and not a json object

Answered
Broken Nokia posted this in #help-forum
Open in Discord
Why am I not able to log the value of "message" key from the response object?
Answered by Zepeto
try to add this
const response = await fetch(url, { cache: "no-cache" });
View full answer

26 Replies

@Zepeto If you log data, what do you get?
@Broken Nokia Click to see attachment
and if you log data.message ?
undefined
@Zepeto and if you log data.message ?
@Broken Nokia Click to see attachment
I reproduced your code but I don't have any issue here
i noticed that mine has the key as a string while yours doesn't

could you please show me the route handler so i can compare it with mine
Can you share your code please ? https://codesandbox.io/
i'm not sure how to work with codesandbox, i'll send the files here?
here's the structure for reference
Or maybe you can directly share your git repos ?
i'll make on github, give me a min
@Broken Nokia i'll make on github, give me a min
take your time no worries 🙂
@Broken Nokia https://github.com/Pushan2005/playground
Maybe try to restart your app
try to add this
const response = await fetch(url, { cache: "no-cache" });
Answer
you're logging data.message?
wow
try to add no-cache en refresh
it worked
i can't list the number of times default caching behaviour has screwed me over so far

thank you 🙏
by default fetch is using cache (this will change in next 15)
@Zepeto by default fetch is using cache (this will change in next 15)
yep, waiting for the stable release just for this haha
have a good day, thank you again