简体   繁体   English

未捕获的错误:元素类型无效:应为字符串

[英]Uncaught Error: Element type is invalid: expected a string

I've tried http://codepen.io/gaearon/pen/VKQwEo?editors=0010 from React's documentation it works fine. 我已经从React的文档中尝试过http://codepen.io/gaearon/pen/VKQwEo?editors=0010 ,它工作正常。

I want to make a button using material-ui. 我想使用material-ui制作一个按钮。 What is wrong with this code? 此代码有什么问题?

    import * as React from "react";   
    import * as ReactDOM from "react-dom";
    import {Router, Route, IndexRoute} from "react-router";

    const FlatButton = require('material-ui/FlatButton');


    function Test(props){
    return(
    <div className="test">
    aaa
    <FlatButton label="Default" />
    </div>
    );
    }

    ReactDOM.render(
    <Test

    />
    , document.getElementById('root')
    );

Errors: 错误:


invariant.js:39 Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of `Test

warning.js:45 Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of `Test`

If ur using material ui component then u need to import MuiThemeProvider, getMuiTheme from material-ui , and wrap ur component by MuiThemeProvider , try this it will work: 如果您使用material ui组件,那么您需要导入material-ui MuiThemeProvider, getMuiTheme ,并通过MuiThemeProvider包装您的组件,请尝试使用此方法:

import React from "react";   
import ReactDOM from "react-dom";
import {Router, Route, IndexRoute} from "react-router";
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
const getMuiTheme = getMuiTheme({});

import FlatButton from 'material-ui';

 const App = (props) => {

    return (
         <FlatButton label='default'  />
    );
  }

ReactDOM.render(
   <MuiThemeProvider muiTheme={getMuiTheme}>
    <App />
  </MuiThemeProvider>,
  document.getElementById('container')
);

check jsfiddle for working example: https://jsfiddle.net/u7yvr564/ 检查jsfiddle的工作示例: https : jsfiddle

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的错误:元素类型无效:应为字符串 - Uncaught Error: Element type is invalid: expected a string Reactjs未捕获的错误:元素类型无效:预期为字符串 - Reactjs Uncaught error: Element type is invalid: expected a string 未捕获的错误:不变违规:元素类型无效:应为字符串 - Uncaught Error: Invariant Violation: Element type is invalid: expected a string 未捕获的错误:元素类型无效:预期为字符串(内置组件)或类/函数(复合组件),但得到:未定义 - Uncaught Error: Element type is invalid: expected a string (built-in components) or a class/function ( composite components) but got: undefined 未捕获的错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义 - Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got:undefined 未捕获的错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数但得到:对象 - Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function but got: object 未捕获的错误:不变违规:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数但得到:object - Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object 未捕获的错误:始终违反:元素类型无效:预期为字符串或类/函数,但得到:对象 - Uncaught Error: Invariant Violation: Element type is invalid: expected a string or a class/function but got: object React Memo功能给出: - 未捕获的错误:元素类型无效:期望一个字符串但得到:object - React Memo Feature gives :- Uncaught Error: Element type is invalid: expected a string but got: object 错误:元素类型无效:应为字符串 - Error: Element type is invalid: expected a string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM