我在控制台中收到此消息:
失败的上下文类型:muiTheme未在中指定 所需的上下文AppBar AppBar.js:158未捕获的TypeError:无法读取未定义的属性’prepareStyles’
失败的上下文类型:muiTheme未在中指定 所需的上下文AppBar
muiTheme
AppBar
AppBar.js:158未捕获的TypeError:无法读取未定义的属性’prepareStyles’
我在组件中只有一个AppBar,我认为它应该可以工作,但是…这是我非常简单的代码:
import React from 'react'; import {AppBar} from 'material-ui'; export class MyComponent extends React.Component { render() { return ( <div> <AppBar title="Title" /> </div> ); } }
感谢您的帮助…
使用[email protected]进行了一些更改。
您可以在下面的链接上查看更多详细信息。 https://github.com/callemall/material- ui/blob/master/CHANGELOG.md
因此,通过这些更改,您的代码将变为:
import React from 'react'; import AppBar from 'material-ui/AppBar'; import baseTheme from 'material-ui/styles/baseThemes/lightBaseTheme'; import getMuiTheme from 'material-ui/styles/getMuiTheme'; export class MyComponent extends React.Component { getChildContext() { return { muiTheme: getMuiTheme(baseTheme) }; } render() { return ( <div> <AppBar title="Title" /> </div> ); } } MyComponent.childContextTypes = { muiTheme: React.PropTypes.object.isRequired, };