Skip to content

Instantly share code, notes, and snippets.

@manjunatha-d
Created May 30, 2018 12:24
Show Gist options
  • Save manjunatha-d/4b6237cfc8dbce68aa750fc295b076a7 to your computer and use it in GitHub Desktop.
Save manjunatha-d/4b6237cfc8dbce68aa750fc295b076a7 to your computer and use it in GitHub Desktop.
import { Component } from 'react';
import PropTypes from 'prop-types';
class ScrollToTopOnMount extends Component {
componentDidMount() {
const { top = 0, left = 0, behavior = 'smooth' } = this.props;
window.scrollTo({
top,
left,
behavior
});
}
render() {
return null;
}
}
ScrollToTopOnMount.propTypes = {
top: PropTypes.number,
left: PropTypes.number,
behavior: PropTypes.string
};
export default ScrollToTopOnMount;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment