元素类型无效REACT



我是REACT的新手,收到以下警告:元素类型无效:应为字符串(用于内置组件(或类/函数(用于复合组件(,但得到的却是:object。您可能忘记了从中定义的文件导出组件,或者您可能混淆了默认导入和命名导入。

import App from "./App";
   6 | //import * as serviceWorker from "./serviceWorker";
   7 | 
>  8 | ReactDOM.render(
   9 |   <BrowserRouter>
  10 |     <App />
  11 |   </BrowserRouter>,

My classes are: (index.js)
import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import App from "./App";
//import * as serviceWorker from "./serviceWorker";
ReactDOM.render(
  <BrowserRouter>
    <App />
  </BrowserRouter>,
  document.getElementById("root")
);
//serviceWorker.unregister();

(App.js(

import React, { Component } from "react";
import { Switch, Route, Link } from "react-router-dom";
import "bootstrap/dist/css/bootstrap.min.css";
import "./App.css";
import AddPatient from "./components/add-patient.component";
import Patient from "./components/patient.component";
import PatientsList from "./components/patient-list.component";
class App extends Component {
  render() {
    return (
      <div>
        <nav className="navbar navbar-expand navbar-dark bg-dark">
          <a href="/doctor/patients" className="navbar-brand">
            ReactApp
          </a>
          <div className="navbar-nav mr-auto">
            <li className="nav-item">
              <Link to={"/doctor/patients"} className="nav-link">
                Patients
              </Link>
            </li>
            <li className="nav-item">
              <Link to={"/doctor/newpatient"} className="nav-link">
                Add Patient
              </Link>
            </li>
          </div>
        </nav>
        <div className="container mt-3">
          <Switch>
            <Route exact path={["/", "/doctor/patients"]} component={PatientsList} />
            <Route exact path="/doctor/newpatient" component={AddPatient} />
            <Route path="/doctor/patient/:id" component={Patient} />
          </Switch>
        </div>
      </div>
    );
  }
}
export default App;

我一直在试图理解这个错误,但到目前为止还没有任何线索,即使在尝试了互联网上建议的多种方法之后。

EDIT:经过进一步检查,您似乎只是错误地导出了应用程序组件。

更改:App.js 中的class App extends Component {

对此:class App extends React.Component {

这应该能解决你的问题。

相关内容

  • 没有找到相关文章

最新更新