Files
react.dev/examples/update-on-async-rendering/updating-state-from-props-before.js
2018-02-07 09:21:38 -08:00

17 lines
355 B
JavaScript

// Before
class ExampleComponent extends React.Component {
state = {
isScrollingDown: false,
};
// highlight-range{1-8}
componentWillReceiveProps(nextProps) {
if (this.props.currentRow !== nextProps.currentRow) {
this.setState({
isScrollingDown:
nextProps.currentRow > this.props.currentRow,
});
}
}
}