You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When SSR-ing a component that uses a global event hook like useWindowScroll, an error is thrown: ReferenceError: window is not defined. This is because useGlobalEvent, references the window object directly in here.
Expected behavior
Hooks using useGlobalEvent should do nothing on the server.
My patch-package file until fixed
diff --git a/node_modules/beautiful-react-hooks/useGlobalEvent.js b/node_modules/beautiful-react-hooks/useGlobalEvent.js
index 3bbf551..a77d01b 100644
--- a/node_modules/beautiful-react-hooks/useGlobalEvent.js+++ b/node_modules/beautiful-react-hooks/useGlobalEvent.js@@ -8,7 +8,7 @@ var useEvent_1 = __importDefault(require("./useEvent"));
* Accepts an event name then returns a callback setter for a function to be performed when the event triggers.
*/
var useGlobalEvent = function (eventName, opts) {
- var target = { current: window }; // that's a bit of a hack but it works+ var target = { current: typeof window === "undefined" ? undefined : null }; // that's a bit of a hack but it works
return (0, useEvent_1.default)(target, eventName, opts);
};
exports.default = useGlobalEvent;
The text was updated successfully, but these errors were encountered:
Describe the bug
When SSR-ing a component that uses a global event hook like useWindowScroll, an error is thrown:
ReferenceError: window is not defined
. This is becauseuseGlobalEvent
, references thewindow
object directly in here.Expected behavior
Hooks using useGlobalEvent should do nothing on the server.
My patch-package file until fixed
The text was updated successfully, but these errors were encountered: