我最近更新了我的材料-ui到版本0.15.4并尝试使其工作。我得到的错误是getMuiTheme不是一个函数,即使文件夹位置包含relvant js文件,我也检查并更新了我对15.3.1的反应,所以希望它不是依赖问题。但我似乎无法弄清楚可能是什么问题。
以下是代码示例:
var React = require('react'),
mui = require('material-ui'),
getMuiTheme = require('material-ui/styles/getMuiTheme'),
LoginDialog = require('./login-dialog.jsx'),
RaisedButton = mui.RaisedButton,
MuiThemeProvider = require('material-ui/styles/MuiThemeProvider'),
darkBaseTheme = require('material-ui/styles/baseThemes/darkBaseTheme');
var Index = React.createClass({
getChildContext: function() {
return {
muiTheme: getMuiTheme(darkBaseTheme),
};
},
childContextTypes: {
muiTheme: React.PropTypes.object
},
render: function() {
return (
<div className="mui-app-canvas home-page-background">
<RaisedButton
className="login-button"
label="Login"
onTouchTap={ this._handleLoginDialog }
linkButton={ false } />
<LoginDialog
ref="loginDialog"
loginUrl={ this.props.loginUrl } />
</div>
)
},
_handleLoginDialog: function() {
this.refs.loginDialog.show();
}
});
module.exports = Index;
答案 0 :(得分:3)
问题是material-ui/styles/getMuiTheme.js
是从ES2015源代码转换而来的,并且您想要的功能将作为默认值导出。
如果您想使用require()
引用此功能,则需要使用default
属性:
getMuiTheme = require('material-ui/styles/getMuiTheme').default