Upgrading React and Form's getDerivedStateFromProps

This commit is contained in:
Jeff Avallone 2018-06-02 13:01:16 -04:00
parent 7a8e90d3ca
commit fd656c8649
2 changed files with 21 additions and 12 deletions

View File

@ -10,20 +10,20 @@ import style from './style.css';
class Form extends React.PureComponent {
state = {
syntax: Object.keys(this.props.syntaxes)[0]
syntax: Object.keys(this.props.syntaxes)[0],
prevProps: {}
}
static getDerivedStateFromProps(nextProps, prevState) {
let changes = null;
static getDerivedStateFromProps(props, state) {
let changes = { prevProps: props };
const { prevProps } = state;
prevState = prevState || {};
if (nextProps.expr && nextProps.expr !== prevState.expr) {
changes = { ...(changes || {}), expr: nextProps.expr };
if (props.expr && props.expr !== prevProps.expr) {
changes.expr = props.expr;
}
if (nextProps.syntax && nextProps.syntax !== prevState.syntax) {
changes = { ...(changes || {}), syntax: nextProps.syntax };
if (props.syntax && props.syntax !== prevProps.syntax) {
changes.syntax = props.syntax;
}
return changes;

View File

@ -7709,8 +7709,8 @@ rc@^1.1.7:
strip-json-comments "~2.0.1"
react-dom@^16.3.0:
version "16.3.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.3.2.tgz#cb90f107e09536d683d84ed5d4888e9640e0e4df"
version "16.4.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.4.0.tgz#099f067dd5827ce36a29eaf9a6cdc7cbf6216b1e"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
@ -7767,7 +7767,7 @@ react-test-renderer@^16.3.0:
prop-types "^15.6.0"
react-is "^16.3.2"
"react@^15.6.2 || ^16.0", react@^16.3.0:
"react@^15.6.2 || ^16.0":
version "16.3.2"
resolved "https://registry.yarnpkg.com/react/-/react-16.3.2.tgz#fdc8420398533a1e58872f59091b272ce2f91ea9"
dependencies:
@ -7776,6 +7776,15 @@ react-test-renderer@^16.3.0:
object-assign "^4.1.1"
prop-types "^15.6.0"
react@^16.3.0:
version "16.4.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.4.0.tgz#402c2db83335336fba1962c08b98c6272617d585"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.0"
read-cache@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/read-cache/-/read-cache-1.0.0.tgz#e664ef31161166c9751cdbe8dbcf86b5fb58f774"