Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react scroll on top while transition

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;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #react #scroll #top #transition
ADD COMMENT
Topic
Name
8+6 =