import { useEffect } from 'react' ; import { useHistory } from 'react-router-dom' ; see CoreAdminRouter example export const useScrollToTop = ( ) => { const history = useHistory < { _scrollToTop ? : boolean ; } > ( ) ; useEffect ( ( ) => history . listen ( ( location , action ) => { if ( action !== 'POP' && location . state ?. _scrollToTop && typeof window != 'undefined' ) { window . scrollTo ( 0 , 0 ) ; } } ) , [ history ] ) ; } ;