我寫了下面的代碼遺漏的類型錯誤:_materialUi.Styles.ThemeManager不是一個函數
import React from 'react';
import mui from 'material-ui';
import injectTapEventPlugin from 'react-tap-event-plugin';
let ThemeManager = new mui.Styles.ThemeManager();
let Colors = mui.Styles.Colors;
injectTapEventPlugin();
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
messages : [{id: 1, text: 'Hi'}, {id: 2, text: 'Hello'}, {id: 3, text: 'World'}, {id: 4, text: 'test'}]
};
}
getChildContext() {
return {
stores: this.props.stores,
muiTheme: ThemeManager.getCurrentTheme()
};
}
componentWillMount() {
ThemeManager.setPalette({
primary1Color: Colors.blue500
});
}
render() {
var messageNodes = this.state.messages.map((message) => {
return (<div key={message.id}>{message.text}</div>);
});
return (<div>{messageNodes}</div>);
}
}
App.childContextTypes = {
stores: React.PropTypes.object,
muiTheme: React.PropTypes.object
};
export default App;
但它不斷拋出錯誤
Uncaught TypeError: _materialUi2.default.Styles.ThemeManager is not a function
我已搜查,並在網上搜索,很多人解決它
https://github.com/callemall/material-ui/issues/1439
但SA我的解決方案不適合我。
我改變常量讓,但仍同樣的問題。我的代碼在github上可用'https://github.com/abhitechdojo/MovieLensReact.git' –
對於誰投了票,我想要一個解釋。 – rambossa
這可能是因爲你發佈了兩個答案;)。自從它是正確的,我就投了你的第一個答案。如果您認爲您發佈的內容有相關性,請將其添加到上述文章中,並刪除此文章以保持清潔。 –