reactjs – 未捕获的错误:不变的违例:元素类型无效:期望的字符串(对于内置组件)或类/函数,但got:object

前端之家收集整理的这篇文章主要介绍了reactjs – 未捕获的错误:不变的违例:元素类型无效:期望的字符串(对于内置组件)或类/函数,但got:object前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我得到这个错误

Uncaught Error: Invariant Violation: Element type is invalid: expected
a string (for built-in components) or a class/function (for composite
components) but got: object.

@H_502_6@

这是我的代码

var React = require('react')
var ReactDOM =  require('react-dom')
var Router = require('react-router')
var Route = Router.Route
var Link = Router.Link

var App = React.createClass({
  render() {
    return (
      <div>
        <h1>App</h1>
        <ul>
          <li><Link to="/about">About</Link></li>
        </ul>
      </div>
    )
  }
})

var About = require('./components/Home')
ReactDOM.render((
  <Router>
    <Route path="/" component={App}>
      <Route path="about" component={About} />
    </Route>
  </Router>
),document.body)

我的Home.jsx文件

var React = require('react');
var RaisedButton = require('material-ui/lib/raised-button');

var Home = React.createClass({
  render:function() {
    return (
        <RaisedButton label="Default" />
    );
  },});

module.exports = Home;
在我的情况下(使用Webpack)它是之间的区别:
import {MyComponent} from '../components/xyz.js';

vs

import MyComponent from '../components/xyz.js';

第二个工作时,第一个导致错误

原文链接:https://www.f2er.com/react/303927.html

猜你在找的React相关文章