Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I cannot use material-ui components after update to [email protected]

Tags:

I got this message in my console:

Failed Context Types: Required context muiTheme was not specified in AppBar

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

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

thanks for helping...

like image 576
Yiman Kaing Avatar asked Apr 30 '16 10:04

Yiman Kaing


1 Answers

With [email protected] a few things were changed.

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,         }; 
like image 184
Antonis Zisis Avatar answered Sep 28 '22 10:09

Antonis Zisis