React:TypeError:Object(…)不是 Material UI 中的函数
2018-06-08
13411
因此,我尝试在我的 React 应用中使用 Material UI。我尝试使用 Material UI 版本 0.20.1 和 0.20.0,但收到此错误消息
TypeError: Object(...) is not a function
它指向此行
export default withStyles(styles)(NavBar);
我只是想创建一个导航栏,我尝试了很多方法。包括从文档中复制,但似乎不起作用。
这是整个组件
import React from 'react';
import { withStyles } from 'material-ui/styles';
import AppBar from 'material-ui/AppBar';
import Toolbar from 'material-ui/Toolbar';
import Typography from 'material-ui/styles/typography';
const styles = theme => ({
root: {
flexGrow: 1,
}
});
const NavBar = (props) => {
const { classes } = props;
return (
<div className={classes.root}>
<AppBar position="static" color="default">
<Toolbar>
<Typography variant="title" color="inherit">
Title
</Typography>
</Toolbar>
</AppBar>
</div>
);
}
export default withStyles(styles)(NavBar);
以下是 app.js 中的代码
import React, { Component } from 'react';
import './App.css';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import NavBar from './components/NavBar/NavBar';
import MovieList from './components/grid/MovieList'
class App extends Component {
render() {
return (
<MuiThemeProvider>
<div className="App">
<NavBar />
<MovieList />
</div>
</MuiThemeProvider>
);
}
}
export default App;
我有两个问题;我该如何修复它以及此错误消息是什么意思。 我知道它需要一个函数,但它想要在哪里。 感谢您的帮助。
编辑: 这是完整的错误消息
TypeError: Object(...) is not a function
./src/components/NavBar/NavBar.js
C:/Users/Pc/Documents/projects/netflix/front_end/
src/components/NavBar/NavBar.js:28
25 | );
26 | }
27 |
> 28 | export default withStyles(styles)(NavBar);
29 | //export default NavBar;
30 |
31 |
View compiled
__webpack_require__
C:/Users/Pc/Documents/projects/netflix/front_end/webpack/bootstrap
32b38f70953f3c9e4ae3:678
675 | };
676 |
677 | // Execute the module function
> 678 | modules[moduleId].call(module.exports, module, module.exports,
hotCreateRequire(moduleId));
679 |
680 | // Flag the module as loaded
681 | module.l = true;
View compiled
fn
C:/Users/Pc/Documents/projects/netflix/front_end/webpack/bootstrap
32b38f70953f3c9e4ae3:88
85 | console.warn("[HMR] unexpected require(" + request + ") from
disposed module " + moduleId);
86 | hotCurrentParents = [];
87 | }
> 88 | return __webpack_require__(request);
89 | };
90 | var ObjectFactory = function ObjectFactory(name) {
91 | return {
View compiled
./src/App.js
http://localhost:3000/static/js/bundle.js:52716:84
__webpack_require__
C:/Users/Pc/Documents/projects/netflix/front_end/webpack/bootstrap
32b38f70953f3c9e4ae3:678
675 | };
676 |
677 | // Execute the module function
> 678 | modules[moduleId].call(module.exports, module, module.exports,
hotCreateRequire(moduleId));
679 |
680 | // Flag the module as loaded
681 | module.l = true;
View compiled
fn
C:/Users/Pc/Documents/projects/netflix/front_end/webpack/bootstrap
32b38f70953f3c9e4ae3:88
85 | console.warn("[HMR] unexpected require(" + request + ") from
disposed module " + moduleId);
86 | hotCurrentParents = [];
87 | }
> 88 | return __webpack_require__(request);
89 | };
90 | var ObjectFactory = function ObjectFactory(name) {
91 | return {
View compiled
./src/index.js
http://localhost:3000/static/js/bundle.js:53044:63
__webpack_require__
C:/Users/Pc/Documents/projects/netflix/front_end/webpack/bootstrap
32b38f70953f3c9e4ae3:678
675 | };
676 |
677 | // Execute the module function
> 678 | modules[moduleId].call(module.exports, module, module.exports,
hotCreateRequire(moduleId));
679 |
680 | // Flag the module as loaded
681 | module.l = true;
View compiled
fn
C:/Users/Pc/Documents/projects/netflix/front_end/webpack/bootstrap
32b38f70953f3c9e4ae3:88
85 | console.warn("[HMR] unexpected require(" + request + ") from
disposed module " + moduleId);
86 | hotCurrentParents = [];
87 | }
> 88 | return __webpack_require__(request);
89 | };
90 | var ObjectFactory = function ObjectFactory(name) {
91 | return {
View compiled
0
http://localhost:3000/static/js/bundle.js:53275:18
__webpack_require__
C:/Users/Pc/Documents/projects/netflix/front_end/webpack/bootstrap
32b38f70953f3c9e4ae3:678
675 | };
676 |
677 | // Execute the module function
> 678 | modules[moduleId].call(module.exports, module, module.exports,
hotCreateRequire(moduleId));
679 |
680 | // Flag the module as loaded
681 | module.l = true;
View compiled
./node_modules/ansi-regex/index.js.module.exports
C:/Users/Pc/Documents/projects/netflix/front_end/webpack/bootstrap
32b38f70953f3c9e4ae3:724
721 | __webpack_require__.h = function() { return hotCurrentHash; };
722 |
723 | // Load entry module and return exports
> 724 | return hotCreateRequire(0)(__webpack_require__.s = 0);
725 |
726 |
727 |
View compiled
(anonymous function)
http://localhost:3000/static/js/bundle.js:728:10