Next.js Discord

Discord Forum

How to get NextResponse body when using fetch api

Answered
Red-necked Grebe posted this in #help-forum
Open in Discord
Original message was deleted.
Answered by Pacific herring
in return NextResponse.json({message: "message you want to pass", status: 200});
View full answer

17 Replies

Avatar
Pacific herring
@Red-necked Grebe
show full code
btw
in the route
you return a response
return NextResponse.json({message: "nothing happened", status: 204});
then in your component you await for it
const result = await res.json();
result.message will return "nothing happened"
it told you
that some data is not a valid json
because you're awaiting for a json
you telling it that it will receive a json
its like you expect me to talk to you in english but then my next message will be in italian
i'd change all your responses
Avatar
Pacific herring
in return NextResponse.json({message: "message you want to pass", status: 200});
Answer
Avatar
Pacific herring
Image