Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

handling scrolling on react router transitions

import { useEffect } from 'react';
import { withRouter } from 'react-router-dom';

function ScrollToTop({ history }) {
  useEffect(() => {
    const unlisten = history.listen(() => {
      window.scrollTo(0, 0);
    });
    return () => {
      unlisten();
    }
  }, []);

  return (null);
}

export default withRouter(ScrollToTop);
Comment

PREVIOUS NEXT
Code Example
Javascript :: draw a rectangle on canvas on pointermove 
Javascript :: H. Nazmul 
Javascript :: remove special characters javascript 
Javascript :: animate flash jQuery 
Javascript :: javascript give class to element 
Javascript :: find the key of a value in array js 
Javascript :: calculate time difference in hrs moment 
Javascript :: set focus on input field javascript 
Javascript :: object to json javascript 
Javascript :: if checkbox is checked jquery 
Javascript :: how select start from id in jquery 
Javascript :: react native curved view 
Javascript :: var data ="<tr<td"+ data.data[i].name"</td"+"<td"+ data.data[i].email"</td"+"<td"+ data.data[i].create_at"</td</tr"; 
Javascript :: check type javascript 
Javascript :: rendering htmnl element to DOM 
Javascript :: js union arrays 
Javascript :: como saber si un checkbox esta seleccionado en jquery 
Javascript :: change list of objects to list js 
Javascript :: express cors 
Javascript :: redirect page using javascript 
Javascript :: js display only date 
Javascript :: string to pascal case 
Javascript :: javascript download string as file 
Javascript :: select tag event listener 
Javascript :: sequelize update record 
Javascript :: reload page 
Javascript :: localstorage save array 
Javascript :: array unique values javascript 
Javascript :: json fetch data doest show 
Javascript :: Clear Cell Value In Google Sheet By App Scripts 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =