material-ui-banner icon indicating copy to clipboard operation
material-ui-banner copied to clipboard

Cannot use with NextJS: 'window' is not defined

Open EliteMasterEric opened this issue 5 years ago • 1 comments
trafficstars

This component cannot be used with NextJS.

Expected Behavior: A simple page should build and render.

Actual Behavior: A ReferenceError: window is not defined is thrown.

CodeSandbox for Minimal Example: https://codesandbox.io/s/nextjs-banner-test-vr6pt?file=/pages/index.js

Notes: I could not locate any code in the repository which uses window directly. It may be used by some module that this component calls.

Version Info:

React v16.13.0
NextJS v9.3.0
material-ui-banner v1.4.3

EliteMasterEric avatar Jun 03 '20 16:06 EliteMasterEric

Workaround:

...
const [Banner, setBanner] = React.useState<React.FC<any>>()
...
React.useEffect(() => {
    setBanner(require('material-ui-banner').Banner)
}, [])
...
<Banner open />

arnm avatar Jul 28 '22 14:07 arnm