chentsulin/sweetalert-react

window is still undefined in serverside rendering

Opened this issue · 0 comments

I use parcel-bundler instead of webpack. I've tried to do so:

import swal from 'sweetalert';
import SweetAlert from 'sweetalert-react'; // eslint-disable-line import/no-extraneous-dependencies
import 'sweetalert/dist/sweetalert.css';
 componentDidMount(){
        if (typeof(window) == 'undefined') global.window = new Object();    
  }
    render(){
       return(
            <div className="ro">
            {
                typeof window !== 'undefined' && (
                <SweetAlert
                    show={this.state.show}
                    title="Demo"     
                /> );
    }

so in this case I want to render sweet alert only in browser. The problem is this error:

node_modules/sweetalert/lib/modules/utils.js:37
  if (window.console) {
  ^

ReferenceError: window is not defined

doesn't global.window avoid the issue?
Thanks