反应错误:错误:元素类型无效

时间:2019-12-22 02:33:57

标签: reactjs

今天早些时候,我尝试运行create-react-app,但出现关于模板以及我的React版本可能过时的错误。因此,我全局删除了React,然后重新安装。我再次运行create-react-app,它又开始工作了。

我后来尝试创建一个应用程序,但我不断收到以下消息:

× 错误:

  

元素类型无效:预期为字符串(对于内置   组件)或类/函数(用于复合组件),但得到:   宾语。您可能忘记了从文件中导出组件   定义,否则您可能混淆了默认导入和命名导入。

检查App的呈现方法。

在使用React之前,我从未收到此消息。到目前为止,这是我的代码:

App.js

import React, { Component } from 'react';
import UserOutput from './Components/UserOutput';
import UserInput from './Components/UserInput'

class App extends Component {
  render() {
    return (
      <div>
        <UserInput />
        <UserOutput username="Test" />


      </div>
    )
  }
};

export default App;

UserOutput.js

import React from 'react';

function UserOutput(props) {
  return <h1>this is my username: {props.username} </h1>;
}

export default UserOutput;

UserInput.js

import React from 'react';

function UserInput() {
    return <input>Name</input>
};

export default UserInput;

我尝试搜索错误修复程序,但找不到解决方案。我相信我可以正确导入所有内容,并且在我的IDE中可以正确导入,但是在浏览器中却出现了错误。

0 个答案:

没有答案