Problems with Material-UI components

久未见 提交于 2019-12-25 07:30:03

问题


I'm trying to use the http://www.material-ui.com/#/components/drawer (Docked Example) component from Material-UI with ReactJS.

I get error an error on the "=" in the following line:

handleToggle = () => this.setState({open: !this.state.open});

I get the same error on some other components as well. I'm using the latest version of Material-UI.

Same with this one: http://www.material-ui.com/#/components/table (Complex Example) on the following code:

handleToggle = (event, toggled) => {

Any ideas?

Thank you.


回答1:


You'll either need to use an ES6 transpiler such as babel to convert your code to JS that current browsers can understand, or not use fat-arrow functions:

handleToggle() {
  this.setState({open: !this.state.open});
};



回答2:


Thanks for the input. I just had to add "stage-0" to my loaders and install "babel-preset-stage-0". Now everything works. Thanks again.



来源:https://stackoverflow.com/questions/37544124/problems-with-material-ui-components

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!