mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-22 20:01:57 +00:00
Renamed params for gDSFP
This commit is contained in:
@@ -186,7 +186,7 @@ If you "fork" props by using them for state, you might also want to implement [`
|
||||
### `static getDerivedStateFromProps()`
|
||||
|
||||
```js
|
||||
static getDerivedStateFromProps(nextProps, prevState)
|
||||
static getDerivedStateFromProps(props, state)
|
||||
```
|
||||
|
||||
`getDerivedStateFromProps` is invoked right before calling the render method, both on the initial mount and on subsequent updates. It should return an object to update the state, or null to update nothing.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Example extends React.Component {
|
||||
static getDerivedStateFromProps(nextProps, prevState) {
|
||||
static getDerivedStateFromProps(props, state) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ class ExampleComponent extends React.Component {
|
||||
};
|
||||
|
||||
// highlight-range{1-13}
|
||||
static getDerivedStateFromProps(nextProps, prevState) {
|
||||
static getDerivedStateFromProps(props, state) {
|
||||
// Store prevId in state so we can compare when props change.
|
||||
// Clear out previously-loaded data (so we don't render stale stuff).
|
||||
if (nextProps.id !== prevState.prevId) {
|
||||
if (props.id !== state.prevId) {
|
||||
return {
|
||||
externalData: null,
|
||||
prevId: nextProps.id,
|
||||
prevId: props.id,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,12 @@ class ExampleComponent extends React.Component {
|
||||
lastRow: null,
|
||||
};
|
||||
|
||||
// highlight-range{1-8}
|
||||
static getDerivedStateFromProps(nextProps, prevState) {
|
||||
if (nextProps.currentRow !== prevState.lastRow) {
|
||||
// highlight-range{1-7}
|
||||
static getDerivedStateFromProps(props, state) {
|
||||
if (props.currentRow !== state.lastRow) {
|
||||
return {
|
||||
isScrollingDown:
|
||||
nextProps.currentRow > prevState.lastRow,
|
||||
lastRow: nextProps.currentRow,
|
||||
isScrollingDown: props.currentRow > state.lastRow,
|
||||
lastRow: props.currentRow,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import {polyfill} from 'react-lifecycles-compat';
|
||||
|
||||
class ExampleComponent extends React.Component {
|
||||
// highlight-next-line
|
||||
static getDerivedStateFromProps(nextProps, prevState) {
|
||||
static getDerivedStateFromProps(props, state) {
|
||||
// Your state update logic here ...
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user