material-ui-banner
material-ui-banner copied to clipboard
Cannot use with NextJS: 'window' is not defined
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
Workaround:
...
const [Banner, setBanner] = React.useState<React.FC<any>>()
...
React.useEffect(() => {
setBanner(require('material-ui-banner').Banner)
}, [])
...
<Banner open />