Skip to content

Commit

Permalink
add effect to set scroll when component mounted (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
afwilcox authored Jul 20, 2023
1 parent bf9880d commit 48c1f52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions frontend/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Roles from "./constants/roles";
import { ComplaintContainer } from "./components/containers/complaints/complaint-container";

import ProtectedRoutes from "./components/routing";
import ScrollToTop from "./common/scroll-to-top";
import NotAuthorized, { NotFound } from "./components/containers/pages";
import { ComplaintDetails } from "./components/containers/complaints/complaint-details";
import ColorReference from "./components/reference";
Expand All @@ -25,6 +26,7 @@ const App: FC = () => {

return (
<Router>
<ScrollToTop />
<Modal />
<Routes>
<Route element={<ProtectedRoutes roles={[Roles.COS_ADMINISTRATOR]} />}>
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/app/common/scroll-to-top.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEffect } from "react";
import { useLocation } from "react-router-dom";

export default function ScrollToTop() {
const { pathname } = useLocation();

useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);

return null;
}

0 comments on commit 48c1f52

Please sign in to comment.