Merge pull request #910 from bvaughn/rename-gdsfp-params

Renamed gDSFP params
This commit is contained in:
Brian Vaughn
2018-05-24 18:24:17 -07:00
committed by GitHub
5 changed files with 11 additions and 12 deletions

View File

@@ -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.

View File

@@ -1,5 +1,5 @@
class Example extends React.Component {
static getDerivedStateFromProps(nextProps, prevState) {
static getDerivedStateFromProps(props, state) {
// ...
}
}

View File

@@ -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,
};
}

View File

@@ -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,
};
}

View File

@@ -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 ...
}
}