更新至material-ui@0.15.0-beta.1后,我无法使用material-ui组件 [英] I cannot use material-ui components after update to material-ui@0.15.0-beta.1

查看:109
本文介绍了更新至material-ui@0.15.0-beta.1后,我无法使用material-ui组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在控制台中收到了此消息:

I got this message in my console:

失败的上下文类型:在中未指定必需的上下文muiTheme AppBar

AppBar.js:158未捕获的TypeError:无法读取属性'prepareStyles' 的未定义

AppBar.js:158 Uncaught TypeError: Cannot read property 'prepareStyles' of undefined

我的组件中只有一个AppBar 我认为应该可以,但是... 这是我非常简单的代码:

I just have an AppBar in my Component I think it should work but... here my very simple code:

import React from 'react';
import {AppBar} from 'material-ui';


    export class MyComponent extends React.Component {

        render() {
            return (
                <div>
                    <AppBar
                        title="Title"
                    />

                </div>
            );
        }

    }

感谢您的帮助...

推荐答案

使用material-ui@0.15.0.beta-1进行了一些更改.

With material-ui@0.15.0.beta-1 a few things were changed.

您可以在下面的链接上查看更多详细信息. https://github.com/callemall/material-ui/blob/master/CHANGELOG.md

You can have a look on the link below for more details. https://github.com/callemall/material-ui/blob/master/CHANGELOG.md

因此,通过这些更改,您的代码将变为:

Therefore with those changes your code becomes:

    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,
        };

这篇关于更新至material-ui@0.15.0-beta.1后,我无法使用material-ui组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆