Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

window is still undefined in serverside rendering #106

Open
ste9206 opened this issue Feb 27, 2018 · 0 comments
Open

window is still undefined in serverside rendering #106

ste9206 opened this issue Feb 27, 2018 · 0 comments

Comments

@ste9206
Copy link

ste9206 commented Feb 27, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant