我得到这个错误:

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.

这是我的代码:

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)

我的家。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;

当前回答

当我更改此代码时,错误已被修复

AppRegistry.registerComponent(appName, App );

到此代码:

AppRegistry.registerComponent(appName, () => App);

其他回答

在我的例子中,导出的子模块之一没有返回正确的react组件。

const Component = <div> Content </div>;

而不是

const Component = () => <div>Content</div>;

显示的错误是针对父进程的,因此无法找出。

就我而言,

//details.js 
import React from 'react'

const Details = (props) =>{
return <h1>Details</h1>
}

export default Details;


//main.js
import React from "react";
import { withRouter } from "react-router";
import {Route,BrowserRouter as Router,Redirect,Switch,Link} from "react-router-dom";
import Details from "./myAccount/details";

const Main = (props) => {
 return (
   <>
        <Switch>
          <Route path="/my-account/details" component={<Details />} />
        </Switch>
   </>

 );
};

export default withRouter(Main);

===========================

Replaced with below one, error got fixed
component={<Details />}  with  component={Details} 

我错误地试图从react-native而不是native-base导入容器和内容。

错误,因为这一行:

import { ActivityIndicator, RefreshControl,  StyleSheet, View, Keyboard, Container, Content } from 'react-native';

下面是代码修复:

import { ActivityIndicator, RefreshControl,  StyleSheet, View, Keyboard } from 'react-native';
import { Container, Content} from 'native-base';

在文件底部导出可以解决这个问题。

const IndicatorCloak = (props) => { ... }
export default IndicatorCloak;

我有同样的问题,问题是一些js文件不包括在该特定页面的捆绑。尝试包括这些文件,问题可能会得到解决。 我是这样做的:

.Include("~/js/" + jsFolder + "/yourjsfile")

它帮我解决了这个问题。

这是当我使用React在Dot NEt MVC