jedireza/aqua

Using Modal component from a main page results in "window is not defined" error

Cornstar23 opened this issue · 3 comments

When trying to create an instance of Modal from, say, the client/main/navbar the server throws a "window is not defined" error. Is there something I might be doing wrong or is this a bug?

Please include stack traces when sharing errors. window is not defined isn't that helpful on it's own.

I do know that the constructor of the Modal component expects the global window to be present, which doesn't exist on the server.

bgHeight: window.innerHeight

The main app is universal (aka isomorphic) and get's rendered on the server. You'd need to modify the Modal component to detect if global.window exists before using it.

Thanks. Not sure if the proper way, but I just moved

this.state = {
   bgHeight: window.innerHeight
};

to the componentDidMount() and set the bgHeight to 0 in the constructor instead of to window.innerHeight.

If it works for you, that's all that matters. 😁