From fd656c864997a6c4c9c428823118b8896baead50 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Sat, 2 Jun 2018 13:01:16 -0400 Subject: [PATCH] Upgrading React and Form's getDerivedStateFromProps --- src/components/Form/index.js | 18 +++++++++--------- yarn.lock | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/components/Form/index.js b/src/components/Form/index.js index 5bbcded..64de036 100644 --- a/src/components/Form/index.js +++ b/src/components/Form/index.js @@ -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; diff --git a/yarn.lock b/yarn.lock index cab2261..a07296a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"