Skip to content

Instantly share code, notes, and snippets.

@itsdouges
Created September 4, 2017 05:46
Show Gist options
  • Save itsdouges/cbf11c28b2f583dd18380313f9c6ea82 to your computer and use it in GitHub Desktop.
Save itsdouges/cbf11c28b2f583dd18380313f9c6ea82 to your computer and use it in GitHub Desktop.
HOC to scroll to to top of the page when mounted
// @flow
import { Component } from 'react';
const withScroll = (WrappedComponent: React.ComponentType<*>) => class ScrollTopOnMount extends Component<void> {
componentDidMount () {
window.scrollTo(0, 0);
}
render () {
return <WrappedComponent {...this.props} />;
}
};
export default withScroll;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment