use-http icon indicating copy to clipboard operation
use-http copied to clipboard

`Response` is not defined in Node

Open thure opened this issue 5 years ago • 7 comments

Describe the bug useFetch crashes the SSR server if the code makes any call to the getter for a response. The getter uses instanceof Response, expecting Reponse on the global namespace, which is undefined in Node.

To Reproduce Steps to reproduce the behavior:

  1. Create a React component that uses useFetch
  2. Add the following to its render function:
const {response} = useFetch('https://localhost:4001')
const responseStatus = response.status
  1. Render using Node

Expected behavior The getter for responses should return the right value whether on the server or on the client.

thure avatar May 06 '20 19:05 thure

I will take a look as soon as possible! Bare with me!

iamthesiz avatar May 08 '20 05:05 iamthesiz

Any movement on this? 🙏

piersolenski avatar Mar 09 '21 09:03 piersolenski

Experiencing the same issue with Gatsby static build render (on server).

Are there any updates on this by chance?

hashinteractive avatar Sep 30 '21 20:09 hashinteractive

Ended up switching to https://react-query.tanstack.com/ - would recommend it!

piersolenski avatar Oct 01 '21 11:10 piersolenski

@piersolenski thanks for the reference!

hashinteractive avatar Oct 01 '21 13:10 hashinteractive

Sorry for the delay guys. I'm extremely busy and haven't had time to debug this. A PR is very much welcomed.

iamthesiz avatar Oct 04 '21 19:10 iamthesiz

I am getting same error after upgrading Gatsby from 2 to 4.

pachkovska avatar Mar 15 '22 01:03 pachkovska