I'm trying to fetch a message from /api pages on NextJS, how do I get the sent response from API to front end?
Example API:
export default function handler(req, res) {
res.status(200).json({ name: 'John Doe' })
}
My API call on front end:
useEffect(() => {
fetch("/api/hello",{method: "GET"}).then((response) => {
console.log(response)
})
}, [])
Response I'm getting:
Why is the name 'John Doe' not appearing here?
When I was on create-react-app, I fetch APIs with axios and console logging response.data gives all the data sent from res.send from backend, but here on NextJS, it doesn't appear on API response