I have a question concerning this particular example where I am using useEffect without dependency array. ESLint complains that it needs "navigate" inside the dependency array or else the dependency array can be removed.
Would this be a use case of useEffect without dependency array since I am unmounting the component after 3 seconds? Am I correct in thinking that we would not risk any re-render by not using a [] in this particular example?
//Home.js
export default function Home {
return <h1>Home</h1>
}
//NotFound.js
import { useEffect} from 'react'
import { useNavigate } from "react-router-dom";
export default function NotFound() {
const navigate = useNavigate();
useEffect(() => {
setTimeout(() => navigate("/"), 3000)
})
return <h1>Not Found</h1>
//App.js
import "./styles.css";
import { Routes, Route } from "react-router-dom";
import NotFound from "./NotFound";
import Home from "./Home.js";
export default function App() {
return (
<div className="App">
<Routes>
<Route path="/" element={<Home />} />
<Route path="*" element={<NotFound />} />
</Routes>
</div>
);
}
It works with both the dependency array containing "navigate" and without the dependency array.