0

While creating the project file I'm getting the specific error - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

https://codesandbox.io/s/agitated-merkle-1m1djh?file=/src/App.js

1 Answers1

0

I don't get why but changing your route method in App.js solved it. replace App.js return statement with this:

 <BrowserRouter>
  <div>
    <Routes>
      <Route path="/" exact={true} element={<Login props={this.props} handleSubmit={handleSubmit} />} />
        
      <Route path="/errorlogin" element={<Errorlogin />} />
        
      <Route path="/tasks" element={<Alltasks tasks={Tasks} />} />
        
    </Routes>
  </div>
</BrowserRouter>

Also a little change in import:

import { BrowserRouter, Routes, Route } from "react-router-dom"

Moreover, importing unwanted items is not good practice. If I am not wrong you have a statement to import ReactDom in App.js file.

Sebak Thapa
  • 171
  • 2
  • 7
  • 1
    This happened because you are using react router v6 and In react-router-dom v6, 'Switch' is replaced by 'Routes'. – Sebak Thapa Apr 20 '23 at 10:30