Skip to content

Instantly share code, notes, and snippets.

@anantl05
Created May 15, 2019 07:30
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 anantl05/090cc41214878379d657ea9b1cd5b890 to your computer and use it in GitHub Desktop.
Save anantl05/090cc41214878379d657ea9b1cd5b890 to your computer and use it in GitHub Desktop.
this.state = {
scrollPosition: 0
}
componentWillReceiveProps () {
const element = ReactDOM.findDOMNode(this);
if (element != null) {
this.setState({
scrollPosition: window.scrollY
})
}
}
componentDidUpdate () {
const element = ReactDOM.findDOMNode(this);
if (element != null) {
window.scrollTo(0, this.state.scrollPosition)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment