Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

scoll to top on each route react

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;
}


function App() {
  return (
    <Router>
      <ScrollToTop />
      <App />
    </Router>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript location redirect target _blank 
Javascript :: autoplay owl carousel 
Javascript :: node check if file exists 
Javascript :: access angular app outside localhost 
Javascript :: tolowercase jquery 
Javascript :: mongodb query to check empty array 
Javascript :: three js cdn 
Javascript :: how to reload page on button click in javascript 
Javascript :: jquery phone number mask 
Javascript :: While trying to resolve module `idb` from file 
Javascript :: jquery responsive 
Javascript :: javascript replace newline with br 
Javascript :: reload page jquery timer 
Javascript :: event exit fullscreen 
Javascript :: fetch post json 
Javascript :: js mouse position relative to element 
Javascript :: ajax get request 
Javascript :: replacing each space in a string javascript 
Javascript :: react native duplicate resources: Android 
Javascript :: react native button round 
Javascript :: return json with jango 
Javascript :: create element javascript save to local storage 
Javascript :: toastr.js cdn 
Javascript :: document ready function 
Javascript :: javascript get table row count 
Javascript :: select random element js array 
Javascript :: remove previous datatable instance 
Javascript :: update nodejs 
Javascript :: jquery tag name 
Javascript :: godot destroy node 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =