Material UI 凸起按钮不起作用

Material UI Raised Button not working

我是从 Material UI (http://www.material-ui.com/#/components/raised-button) 中逐字复制凸起按钮的代码。我已经安装了所有必要的节点模块。发生了什么事?

附上图片下方的错误。基本上它说 "TypeError: Cannot read property 'prepareStyles' of undefined".

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

您的 style 属性似乎未定义。请查看 document page 的代码:

import React from 'react';
import RaisedButton from 'material-ui/RaisedButton';

const style = {
  margin: 12,
};

const RaisedButtonExampleSimple = () => (
  <div>
    <RaisedButton label="Default" style={style} />
    <RaisedButton label="Primary" primary={true} style={style} />
    <RaisedButton label="Secondary" secondary={true} style={style} />
    <RaisedButton label="Disabled" disabled={true} style={style} />
    <br />
    <br />
    <RaisedButton label="Full width" fullWidth={true} />
  </div>
);

export default RaisedButtonExampleSimple;

有一个不变的风格:

const style = {
  margin: 12,
};

您需要将最顶层的组件(或至少一些父组件)包装在 material-ui的MuiThemeProvider组件:

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

这个问题应该被关闭或否决,因为它已经在这里被询问和回答:

我没有处理此问题所需的代表,但我们不应该在这里对同一件事提出多个问题。