Created
September 8, 2016 22:16
-
-
Save MoOx/92733134233c8bacfc43385569a50d8f to your computer and use it in GitHub Desktop.
avoid "windows is undefined" error when in node for React component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react" | |
import styles from "./index.css" | |
export default class Hero extends Component { | |
componentDidMount() { | |
if (typeof window !== "undefined") { | |
require("particles.js").particlesJS.load("particles-js", "assets/particles.json", function() { | |
console.log("callback - particles.js config loaded") | |
}) | |
} | |
} | |
render() { | |
return ( | |
<div id="particles-js" className={ styles.container }> | |
<header className={ styles.header }> | |
{ "Scale Conf" } | |
</header> | |
</div> | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mport React, { Component } from "react" | |
let particles | |
if (typeof window !== "undefined") { | |
particles = require("particles.js") | |
} | |
import styles from "./index.css" | |
export default class Hero extends Component { | |
componentDidMount() { | |
particles && .particlesJS.load("particles-js", "assets/particles.json", function() { | |
console.log("callback - particles.js config loaded") | |
}) | |
} | |
render() { | |
return ( | |
<div id="particles-js" className={ styles.container }> | |
<header className={ styles.header }> | |
{ "Scale Conf" } | |
</header> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment