javascript - React JS 和material-ui 错误

标签 javascript reactjs material-ui

我想将material-ui与reactjs一起使用。当我想要渲染 FlatButton 时,出现以下错误: TypeError: _context$muiTheme is undefined

我是reactjs的新手,我不知道可能是什么错误。这是我的代码:

import React, {Component} from 'react'
import { Alert, Button, Jumbotron,  Form } from 'reactstrap';
import FlatButton from 'material-ui/FlatButton';
import TextInput from './TextInput'

export default class LoginForm extends Component {
  state = {
    username: '',
    password: ''
  }

  handleInputChange = (event) => {
    const target = event.target;
    const value = target.type ===
        'checkbox' ? target.checked : target.value;
    const name = target.name;

    this.setState({
      [name]: value
    });
  }

  componentDidMount() {
    this.primaryInput.focus();
  }

  onSubmit = (event) => {
    event.preventDefault()
    this.props.onSubmit(this.state.username, this.state.password)
  }

  render() {
    const errors = this.props.errors || {}

    return (
        <Form onSubmit={this.onSubmit}>
          {errors.non_field_errors?<Alert color="danger">{errors.non_field_errors}</Alert>:""}
          <TextInput name="username" label="Username" error={errors.username} getRef={input => this.primaryInput = input} onChange={this.handleInputChange}/>
          <TextInput name="password" label="Password" error={errors.password} type="password" onChange={this.handleInputChange}/>
          <FlatButton label="Primary" type="submit" primary={true} />
        </Form>

    )
  }
}

有什么想法吗?

谢谢。

最佳答案

docs假设您需要使用 MuiThemeProvider 作为应用程序的包装器。

例如:

import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import FlatButton from 'material-ui/FlatButton';

<MuiThemeProvider>
  <FlatButton label="Primary" type="submit" primary={true} />
</MuiThemeProvider>

关于javascript - React JS 和material-ui 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47161610/

相关文章:

javascript - 对齐屏幕 ionic html右下角的按钮

javascript - 正确的 HTML 链接不起作用(最后 7 个字符在浏览器中被剪切)?

javascript - React Router 4 和 props.history.push

javascript - 从组件数组中删除组件

javascript - 使用动态表单/网页编辑数据库的内容

javascript - 从 JSON 对象创建新的 jQuery 数组

html - 为什么 CSS 文件没有加载到 React 应用程序中

material-ui - 无法覆盖 Material UI Typography fontWeight

javascript - 使用 MakeStyles 更改 SVG 填充颜色 : how to choose specific IDs in SVG file using Selectors?

typescript - 如何将 MarkerClusterer 添加到 google-map-react