在反应中获取错误元素类型无效

时间:2020-03-12 09:37:50

标签: reactjs

App.js

    import './App.css';
    import { BrowserRouter as Router, Route } from "react-dom";
    import SignInForm from "./components/SignInForm";
    import Login from "./login.svg";   
    function App() {
      return (
       <Router>
         <div className="App">

          <div className="App__Aside"></div>

          <div className="App__Form">

            <div className="PageSwitcher">

              <a href="#" className="PageSwitcher__Item">Sing In</a>
              <a href="#" className="PageSwitcher__Item PageSwitcher__Item--Active">Sign Up</a>

           </div>

           <div className="Form__Logo">
             <img src={Login}/>
           </div>

           <Route exact path="/" component={SignInForm}>
           </Route>

         </div>

        </div>
    </Router>
    );
  }

  export default App;

SignInForm.js

    import React, { Component } from "react";
    class SingInForm extends Component {
         render() {
              return (
                  <div className="FormCenter">
                  <form className="FormFields">
                     <div className="FormField">
                        <label className="FormField__Label" htmlFor="username">Username</label>
                        <input type="text" id="username" className="FormField__Input" placeholder="Enter username" name="username"/>
                     </div>
                  </form>
                  </div>
            );
         }
     }
    export default SingInForm;

期望一个字符串(对于内置组件)或一个类/函数(对于 复合组件),但得到:未定义。您可能忘记了出口 您的组件来自定义它的文件,或者您可能已经混合使用 设置默认名称并命名导入。

2 个答案:

答案 0 :(得分:3)

BrowserRouterRoute Navlink等是从react-router-dom导出的。

在您的代码库中,更改以下导入语句-

import { BrowserRouter as Router, Route } from "react-dom";

至-

import { BrowserRouter as Router, Route } from "react-router-dom";

答案 1 :(得分:0)

App.js

import SignInForm from "./components/SignInForm";

import SignInForm from "./components/SigninForm";

错误的文件将 SigninForm.js 导入了文件。