When we are using SSR, we have to be very careful when we try to use the object window for the client. If you use it directly using SSR you will get a ReferenceError such as this:
ReferenceError: window is not defined
To solve this problem, you can validate that the window object exists, but this can be very repetitive. I prefer to create a function that can verify whether we are using a browser (client) or a server. You can do it like this:
export function isBrowser() { return typeof window !== 'undefined'; }
Then every time you need to use the window object, you can do something like this:
const store = isBrowser() ? configureStore(window.initialState) : {};