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
how to fix "window is not defined" when use webpack build ? #162
Comments
Same question here. |
I'm having the same issue when trying to test via jest.
|
thlorenz/brace#40 (comment) ==> if anyone wanna try |
I want to make sure i understand. Are you all rendering on the server? Or just a traditional webpack build? |
You can easily use a stub const Editor = (props) => {
if (typeof window !== 'undefined') {
const Ace = require('react-ace').default;
require('brace/mode/javascript');
require('brace/theme/github');
return <Ace {...props}/>
}
return null;
}
//use it
<Editor mode="javascript" theme="github" value="const foo = 42;" /> And if you want isomorphic code (to remove the warning because here on server side we have class IsomorphicEditor extends React.Component {
state = {mounted: false};
componentDidMount() {
this.setState({mounted: true});
}
render = () => (this.state.mounted ? <Editor {...this.props} /> : null);
} |
@jnoleau It works. But I wonder if there is a better way to solve this problem? |
This works but be warned: do not use variables in your OK (loads one module):
BAD (loads all theme modules):
|
tks
The text was updated successfully, but these errors were encountered: