mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 12:13:11 +00:00
Added explicit null value in state initializer
This commit is contained in:
@@ -2,18 +2,19 @@
|
||||
class ExampleComponent extends React.Component {
|
||||
// Initialize state in constructor,
|
||||
// Or with a property initializer.
|
||||
// highlight-range{1-3}
|
||||
// highlight-range{1-4}
|
||||
state = {
|
||||
isScrollingDown: false,
|
||||
lastRow: null,
|
||||
};
|
||||
// highlight-line
|
||||
// highlight-range{1-8}
|
||||
static getDerivedStateFromProps(nextProps, prevState) {
|
||||
if (nextProps.currentRow !== prevState.lastRow) {
|
||||
return {
|
||||
lastRow: nextProps.currentRow,
|
||||
isScrollingDown:
|
||||
nextProps.currentRow > prevState.lastRow,
|
||||
lastRow: nextProps.currentRow,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user