Created
July 12, 2019 14:00
-
-
Save watadarkstar/8c626c3c271e26f6ca6cdacac9cd9fb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from 'react'; | |
import PropTypes from 'prop-types'; | |
function withScrollToTop(Component) { | |
function Wrapped({ location, ...rest }) { | |
const { pathname } = location; | |
useEffect(() => { | |
window.scrollTo(0, 0); | |
}, [pathname]); | |
return <Component location={location} {...rest} />; | |
} | |
Wrapped.propTypes = { | |
location: PropTypes.object.isRequired, | |
}; | |
return Wrapped; | |
} | |
export default withScrollToTop; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment