Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chris-kobrzak
Last active June 25, 2018 21:42
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 chris-kobrzak/708f31976be5fac2aa265816d6a03f2a to your computer and use it in GitHub Desktop.
Save chris-kobrzak/708f31976be5fac2aa265816d6a03f2a to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import { withRouter } from 'react-router'
const topCoordinates = [0, 0]
const { scrollTo } = window
class ScrollToTopHandler extends Component {
// Arrow method, requires stage 2 Babel preset
render = () => null
componentDidUpdate (prevProps) {
if (this.props.location === prevProps.location) {
return
}
scrollTo(...topCoordinates)
}
}
export default withRouter(ScrollToTopHandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment