Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error 'Router' cannot be used as a JSX component. #207

Open
Blaz-Strusnik opened this issue Aug 21, 2023 · 2 comments
Open

Typescript error 'Router' cannot be used as a JSX component. #207

Blaz-Strusnik opened this issue Aug 21, 2023 · 2 comments

Comments

@Blaz-Strusnik
Copy link

Blaz-Strusnik commented Aug 21, 2023

Failed to compile.

/app/src/index.tsx
TypeScript error in /app/src/index.tsx(8,4):
'Router' cannot be used as a JSX component.
Its instance type 'BrowserRouter' is not a valid JSX element.
The types returned by 'render()' are incompatible between these types.
Type 'React.ReactNode' is not assignable to type 'import("/node_modules/@types/react-transition-group/node_modules/@types/react/ts5.0/index").ReactNode'. TS2786

     6 | 
     7 | ReactDOM.render(
  >  8 |   <Router>
       |    ^
     9 |     <App />
    10 |   </Router>,
    11 |   document.getElementById('root')
Blaz-Strusnik added a commit to Blaz-Strusnik/fastapi-react that referenced this issue Aug 21, 2023
@itsMagondu
Copy link

+1

@Robowizx
Copy link

Robowizx commented Feb 4, 2024

The issue is occurring due to using old type definitions of React and react router. Can upgrade the types packages under the package.json file to newer ones to avoid getting that error. I personally upgraded the following to fix it.

"@types/react": "^18.2.52",
"@types/react-dom": "^18.2.18",
"@types/react-router-dom": "^5.3.3",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants