Muhammad Maaz
Muhammad Maaz

Reputation: 11

Uncaught Runtime error: Cannot read properties of null (reading 'useRef')

I am facing an error like this everything works fine, it's compiled successfully but the app does not display on the browser and appears: "Uncaught Runtime error: Cannot read properties of null (reading 'useRef')"

This is my code:

import Navbar from './components/Navbar'
import {BrowserRouter as Router, Route, Routes } from 'react-router-dom'

function App() {

  return (
    <div className="App">
      <Router>
        <Navbar />
        <Routes>
          <Route></Route>
        </Routes>
      </Router>
    </div>
  );
}

export default App;

before using this: "import {BrowserRouter as Router, Route, Routes } from 'react-router-dom'" it was all fine. Now, If I remove this import and Router, Routes, Route, it works fine. I also installed react-router-dom but the error remains. I was starting to build the app but I received this error.

this is the error that appears on browser

Upvotes: 0

Views: 2982

Answers (1)

Muhammad Maaz
Muhammad Maaz

Reputation: 11

I have solved my problem. Firstly I used the command npm install react-hook-form but the error remains after using this.. Then I just opened a PowerShell window in the root folder of my app where I have package.json, src and other files and then I used npm install react-router-dom and it added 3 packages. Now it's working well and good. I hope it helps others having the same issue.

Upvotes: 0

Related Questions