Skip to content

Instantly share code, notes, and snippets.

@nightspirit
Created April 11, 2018 08:52
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 nightspirit/1d878781cc4a1aae5cbf24812851bbd9 to your computer and use it in GitHub Desktop.
Save nightspirit/1d878781cc4a1aae5cbf24812851bbd9 to your computer and use it in GitHub Desktop.
// before
componentWillReceiveProps(nextProps) {
if (this.props.currentRow !== nextProps.currentRow) {
this.setState({
isScrollingDown: nextProps.currentRow > this.props.currentRow
})
}
}
// after
static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.currentRow !== prevState.lastRow) {
return {
isScrollingDown: nextProps.currentRow > prevState.lastRow,
lastRow: nextProps.currentRow
}
}
// Return null to indicate no change to state.
return null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment