Reactjs – Material UI Raised Button not working

material-uireactjs

I'm literally copying the code verbatim from Material UI (http://www.material-ui.com/#/components/raised-button) for the raised button. I've installed all the necessary node modules. What is happening?

Attached the error below image. Basically it says "TypeError: Cannot read property 'prepareStyles' of undefined".

enter image description here

<RaisedButton label="Primary" primary={true} style={style} />

Best Answer

You need to wrap your topmost component (or at least some parent component) in material-ui's MuiThemeProvider component:

https://jsfiddle.net/9017dsc2/1/

import React from 'react';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';

class Example extends React.Component {
  render() {
    return (
      <div>
        <RaisedButton label="A Raised Button" />
      </div>
    );
  }
}

const App = () => (
  <MuiThemeProvider>
    <Example />
  </MuiThemeProvider>
);
Related Topic