Browse Source
Merge pull request #910 from bvaughn/rename-gdsfp-params
Renamed gDSFP params
main
Brian Vaughn
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
11 additions and
12 deletions
content/docs/reference-react-component.md
examples/update-on-async-rendering/definition-getderivedstatefromprops.js
examples/update-on-async-rendering/updating-external-data-when-props-change-after.js
examples/update-on-async-rendering/updating-state-from-props-after.js
examples/update-on-async-rendering/using-react-lifecycles-compat.js
@ -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, prevS tate)
static getDerivedStateFromProps(props, s tate)
```
`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 , prevS tate) {
static getDerivedStateFromProps ( props , s tate) {
// ...
}
}
@ -5,13 +5,13 @@ class ExampleComponent extends React.Component {
} ;
// highlight-range{1-13}
static getDerivedStateFromProps ( nextProps , prevS tate) {
static getDerivedStateFromProps ( props , s tate) {
// Store prevId in state so we can compare when props change.
// Clear out previously-loaded data (so we don't render stale stuff).
if ( nextP rops. id !== prevS tate. prevId ) {
if ( p rops. id !== s tate. prevId ) {
return {
externalData : null ,
prevId : nextP rops. id ,
prevId : p rops. id ,
} ;
}
@ -8,13 +8,12 @@ class ExampleComponent extends React.Component {
lastRow : null ,
} ;
// highlight-range{1-8 }
static getDerivedStateFromProps ( nextProps , prevS tate) {
if ( nextP rops. currentRow !== prevS tate. lastRow ) {
// highlight-range{1-7 }
static getDerivedStateFromProps ( props , s tate) {
if ( p rops. currentRow !== s tate. 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 , prevS tate) {
static getDerivedStateFromProps ( props , s tate) {
// Your state update logic here ...
}
}