From dba4f04c868b25fce54add77d3c18c4be331d5e2 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sat, 5 Dec 2020 12:05:53 -0500 Subject: [PATCH 1/2] Remove usage of UNSAFE React method --- dist/react-input-autosize.es.js | 20 ++++++++++---------- dist/react-input-autosize.js | 20 ++++++++++---------- dist/react-input-autosize.min.js | 2 +- lib/AutosizeInput.js | 21 +++++++++++---------- src/AutosizeInput.js | 11 +++++------ 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/dist/react-input-autosize.es.js b/dist/react-input-autosize.es.js index d97707c..b084301 100644 --- a/dist/react-input-autosize.es.js +++ b/dist/react-input-autosize.es.js @@ -246,6 +246,14 @@ var generateId = function generateId() { var AutosizeInput = function (_Component) { inherits(AutosizeInput, _Component); + createClass(AutosizeInput, null, [{ + key: 'getDerivedStateFromProps', + value: function getDerivedStateFromProps(props, state) { + var id = props.id; + + return id !== state.prevId ? { inputId: id || generateId(), prevId: id } : null; + } + }]); function AutosizeInput(props) { classCallCheck(this, AutosizeInput); @@ -269,7 +277,8 @@ var AutosizeInput = function (_Component) { _this.state = { inputWidth: props.minWidth, - inputId: props.id || generateId() + inputId: props.id || generateId(), + prevId: props.id }; return _this; } @@ -281,15 +290,6 @@ var AutosizeInput = function (_Component) { this.copyInputStyles(); this.updateInputWidth(); } - }, { - key: 'UNSAFE_componentWillReceiveProps', - value: function UNSAFE_componentWillReceiveProps(nextProps) { - var id = nextProps.id; - - if (id !== this.props.id) { - this.setState({ inputId: id || generateId() }); - } - } }, { key: 'componentDidUpdate', value: function componentDidUpdate(prevProps, prevState) { diff --git a/dist/react-input-autosize.js b/dist/react-input-autosize.js index 9460b91..2ad4ad4 100644 --- a/dist/react-input-autosize.js +++ b/dist/react-input-autosize.js @@ -252,6 +252,14 @@ var generateId = function generateId() { var AutosizeInput = function (_Component) { inherits(AutosizeInput, _Component); + createClass(AutosizeInput, null, [{ + key: 'getDerivedStateFromProps', + value: function getDerivedStateFromProps(props, state) { + var id = props.id; + + return id !== state.prevId ? { inputId: id || generateId(), prevId: id } : null; + } + }]); function AutosizeInput(props) { classCallCheck(this, AutosizeInput); @@ -275,7 +283,8 @@ var AutosizeInput = function (_Component) { _this.state = { inputWidth: props.minWidth, - inputId: props.id || generateId() + inputId: props.id || generateId(), + prevId: props.id }; return _this; } @@ -287,15 +296,6 @@ var AutosizeInput = function (_Component) { this.copyInputStyles(); this.updateInputWidth(); } - }, { - key: 'UNSAFE_componentWillReceiveProps', - value: function UNSAFE_componentWillReceiveProps(nextProps) { - var id = nextProps.id; - - if (id !== this.props.id) { - this.setState({ inputId: id || generateId() }); - } - } }, { key: 'componentDidUpdate', value: function componentDidUpdate(prevProps, prevState) { diff --git a/dist/react-input-autosize.min.js b/dist/react-input-autosize.min.js index 48ff768..d6b48b0 100644 --- a/dist/react-input-autosize.min.js +++ b/dist/react-input-autosize.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],e):t.AutosizeInput=e(t.React,t.PropTypes)}(this,function(t,e){"use strict";var n="default"in t?t.default:t;e=e&&e.hasOwnProperty("default")?e.default:e;!function(){function t(t){this.value=t}function e(e){var n,i;function o(n,i){try{var s=e[n](i),u=s.value;u instanceof t?Promise.resolve(u.value).then(function(t){o("next",t)},function(t){o("throw",t)}):r(s.done?"return":"normal",s.value)}catch(t){r("throw",t)}}function r(t,e){switch(t){case"return":n.resolve({value:e,done:!0});break;case"throw":n.reject(e);break;default:n.resolve({value:e,done:!1})}(n=n.next)?o(n.key,n.arg):i=null}this._invoke=function(t,e){return new Promise(function(r,s){var u={key:t,arg:e,resolve:r,reject:s,next:null};i?i=i.next=u:(n=i=u,o(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}();var i=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},o=function(){function t(t,e){for(var n=0;n=0||Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}(this.props,[]);return function(t){p.forEach(function(e){return delete t[e]})}(o),o.className=this.props.inputClassName,o.id=this.state.inputId,o.style=i,n.createElement("div",{className:this.props.className,style:e},this.renderStyles(),n.createElement("input",r({},o,{ref:this.inputRef})),n.createElement("div",{ref:this.sizerRef,style:u},t),this.props.placeholder?n.createElement("div",{ref:this.placeHolderSizerRef,style:u},this.props.placeholder):null)}}]),h}();return h.defaultProps={minWidth:1,injectStyles:!0},h}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],e):t.AutosizeInput=e(t.React,t.PropTypes)}(this,function(t,e){"use strict";var n="default"in t?t.default:t;e=e&&e.hasOwnProperty("default")?e.default:e;!function(){function t(t){this.value=t}function e(e){var n,i;function r(n,i){try{var s=e[n](i),u=s.value;u instanceof t?Promise.resolve(u.value).then(function(t){r("next",t)},function(t){r("throw",t)}):o(s.done?"return":"normal",s.value)}catch(t){o("throw",t)}}function o(t,e){switch(t){case"return":n.resolve({value:e,done:!0});break;case"throw":n.reject(e);break;default:n.resolve({value:e,done:!1})}(n=n.next)?r(n.key,n.arg):i=null}this._invoke=function(t,e){return new Promise(function(o,s){var u={key:t,arg:e,resolve:o,reject:s,next:null};i?i=i.next=u:(n=i=u,r(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}();var i=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},r=function(){function t(t,e){for(var n=0;n=0||Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}(this.props,[]);return function(t){p.forEach(function(e){return delete t[e]})}(r),r.className=this.props.inputClassName,r.id=this.state.inputId,r.style=i,n.createElement("div",{className:this.props.className,style:e},this.renderStyles(),n.createElement("input",o({},r,{ref:this.inputRef})),n.createElement("div",{ref:this.sizerRef,style:u},t),this.props.placeholder?n.createElement("div",{ref:this.placeHolderSizerRef,style:u},this.props.placeholder):null)}}]),f}();return f.defaultProps={minWidth:1,injectStyles:!0},f}); diff --git a/lib/AutosizeInput.js b/lib/AutosizeInput.js index 0fc5344..cbeba78 100644 --- a/lib/AutosizeInput.js +++ b/lib/AutosizeInput.js @@ -65,6 +65,15 @@ var generateId = function generateId() { var AutosizeInput = function (_Component) { _inherits(AutosizeInput, _Component); + _createClass(AutosizeInput, null, [{ + key: 'getDerivedStateFromProps', + value: function getDerivedStateFromProps(props, state) { + var id = props.id; + + return id !== state.prevId ? { inputId: id || generateId(), prevId: id } : null; + } + }]); + function AutosizeInput(props) { _classCallCheck(this, AutosizeInput); @@ -87,7 +96,8 @@ var AutosizeInput = function (_Component) { _this.state = { inputWidth: props.minWidth, - inputId: props.id || generateId() + inputId: props.id || generateId(), + prevId: props.id }; return _this; } @@ -99,15 +109,6 @@ var AutosizeInput = function (_Component) { this.copyInputStyles(); this.updateInputWidth(); } - }, { - key: 'UNSAFE_componentWillReceiveProps', - value: function UNSAFE_componentWillReceiveProps(nextProps) { - var id = nextProps.id; - - if (id !== this.props.id) { - this.setState({ inputId: id || generateId() }); - } - } }, { key: 'componentDidUpdate', value: function componentDidUpdate(prevProps, prevState) { diff --git a/src/AutosizeInput.js b/src/AutosizeInput.js index f2b1333..81f033a 100644 --- a/src/AutosizeInput.js +++ b/src/AutosizeInput.js @@ -45,11 +45,16 @@ const generateId = () => { }; class AutosizeInput extends Component { + static getDerivedStateFromProps(props, state) { + const { id } = props; + return id !== state.prevId ? { inputId: id || generateId(), prevId: id } : null; + } constructor (props) { super(props); this.state = { inputWidth: props.minWidth, inputId: props.id || generateId(), + prevId: props.id, }; } componentDidMount () { @@ -57,12 +62,6 @@ class AutosizeInput extends Component { this.copyInputStyles(); this.updateInputWidth(); } - UNSAFE_componentWillReceiveProps (nextProps) { - const { id } = nextProps; - if (id !== this.props.id) { - this.setState({ inputId: id || generateId() }); - } - } componentDidUpdate (prevProps, prevState) { if (prevState.inputWidth !== this.state.inputWidth) { if (typeof this.props.onAutosize === 'function') { From f0b063388f2398815fc2bf676474cde19c6355a0 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sat, 5 Dec 2020 16:07:10 -0500 Subject: [PATCH 2/2] Update peerDependency on React --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 691dd4a..b6d8f26 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,8 @@ "less-loader": "^4.0.5", "nps": "^5.7.1", "nps-utils": "^1.3.0", - "react": "^15.0", - "react-dom": "^15.0", + "react": "^16.3.0", + "react-dom": "^16.3.0", "rollup": "^0.49.2", "rollup-plugin-babel": "^3.0.2", "rollup-plugin-commonjs": "^8.2.0", @@ -51,7 +51,7 @@ "webpack-dev-server": "^2.7.1" }, "peerDependencies": { - "react": "^0.14.9 || ^15.3.0 || ^16.0.0-rc || ^16.0" + "react": "^16.3.0 || ^17.0.0" }, "scripts": { "build": "NODE_ENV=production nps build",