Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Youtube in React: scrolling to top when URL changes
import React from 'react';
import {withRouter} from 'react-router-dom';
export class ScrollToTop extends React.Component {
componentDidUpdate(prevProps) {
if (this.props.location !== prevProps.location && window) {
window.scrollTo(0, 0);
}
}
render() {
return this.props.children;
}
}
export default withRouter(ScrollToTop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.