jaydenseric / graphql-react

A GraphQL client for React using modern context and hooks APIs that is lightweight (< 4 kB) but powerful; the first Relay and Apollo alternative with server side rendering.
https://npm.im/graphql-react
MIT License
717 stars 22 forks source link

Wrong type calculation on useGraphQL #49

Closed etc-tiago closed 4 years ago

etc-tiago commented 4 years ago

The date object cannot be subtracted

this https://github.com/jaydenseric/graphql-react/blob/84509154cb6ed72ea1d571f0355bedc2626281cc/src/universal/useGraphQL.js#L205

should be

new Date().getTime() - firstRenderDate < 1000
jaydenseric commented 4 years ago

While it might be good to use something less confusing than new Date() (i.e. Date.now()), it is perfectly valid to do subtraction math on Date instances because they implement @@toPrimitive. See “Why can I do math with Date objects?” on Stack Overflow.

Thanks for the concern though, and looking over the details! Maybe we can tweak it to be less confusing :)