cereallarceny / cra-ssr

[DEPRECATED] Server-side rendering with create-react-app, React Router v4, Helmet, Redux, and Thunk
484 stars 118 forks source link

ReferenceError: window is not defined when i use window.onscroll = function(){ ssr #45

Closed heshamelmasry77 closed 5 years ago

heshamelmasry77 commented 5 years ago

can somebody help me fix this problem

 window.onscroll = function(){

      console.log ('test');
evgenyantipin commented 5 years ago

@heshamelmasry77 try this one import root from "window-or-global"; root.onscroll = function(){ console.log ('test'); }

cereallarceny commented 5 years ago

This is because window doesn't exist on the server. It cannot be used for server-side rendering.