From d2d8cec9eb1a91d80f8f9040e4515618df877212 Mon Sep 17 00:00:00 2001 From: Sohini_Das Date: Sat, 4 Jan 2025 03:16:25 +0530 Subject: [PATCH] Added Scroll-To-Top feature to the website-175 --- src/App.js | 3 +++ src/componets/ScrollToTop.js | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/componets/ScrollToTop.js diff --git a/src/App.js b/src/App.js index 7d3f202..04df874 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,6 @@ import React from 'react'; import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; +import ScrollToTop from './componets/ScrollToTop'; import { Provider } from 'react-redux'; import { store } from './Store/index'; import styled from 'styled-components'; @@ -39,9 +40,11 @@ function App() { return ( + + } /> } /> diff --git a/src/componets/ScrollToTop.js b/src/componets/ScrollToTop.js new file mode 100644 index 0000000..cb777d3 --- /dev/null +++ b/src/componets/ScrollToTop.js @@ -0,0 +1,13 @@ +import { useEffect } from 'react'; +import { useLocation } from 'react-router-dom'; + +const ScrollToTop = () => { + const location = useLocation(); + + useEffect(() => { + window.scrollTo(0, 0); + }, [location]); + return null; +}; + +export default ScrollToTop;