Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silviopaganini/dc817ac9e09c62d7510481ad19747cb7 to your computer and use it in GitHub Desktop.
Save silviopaganini/dc817ac9e09c62d7510481ad19747cb7 to your computer and use it in GitHub Desktop.
ScrollToTop
import { Component } from 'react';
import PropTypes from 'prop-types';
export default class ScrollToTop extends Component {
static propTypes = {
children: PropTypes.element,
}
static defaultProps = {
children: null,
}
componentDidMount() {
window.scrollTo(0, 0);
}
render() {
if (!this.props.children) return null;
return this.props.children;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment