Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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