reactjs / server-components-demo

Demo app of React Server Components.
https://reactjs.org/server-components
MIT License
4.27k stars 640 forks source link

fix: JSON.parse fails in react-fetch #50

Closed rgbkids closed 2 years ago

rgbkids commented 3 years ago

JSON.parse fails in react-fetch

JSON.parse (empty data) doesn't work properly when I get empty data. In react-fetch, I get Uncaught Syntax Error.

fetch(`http://localhost:4000/notes/-1`)

res.json(rows[0]);

Just escape it like this

res.json(rows[0] || "null");

https://stackoverflow.com/questions/9158665/json-parse-fails-in-google-chrome

gaearon commented 2 years ago

why is the data empty?

gaearon commented 2 years ago

i'll close because it's not supposed to be empty. if there's some case where it's empty let's figure out why.

rgbkids commented 2 years ago

Please read this.

fix: JSON.parse fails in react-fetch #55