Skip to content

Commit

Permalink
Prevent cascading updates in componentDidUpdate (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
izhan authored Mar 4, 2020
1 parent 69222e3 commit b9a9e17
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Cleave.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ var cleaveReactClass = CreateReactClass({
this.init();
},

componentDidUpdate: function () {
componentDidUpdate: function (prevProps) {
var owner = this,
phoneRegionCode = (owner.props.options || {}).phoneRegionCode,
newValue = owner.props.value,
pps = owner.properties;

owner.updateRegisteredEvents(owner.props);
if (newValue !== undefined && newValue !== null) {

if (prevProps.value !== newValue && newValue !== undefined && newValue !== null) {
newValue = newValue.toString();

if (newValue !== owner.properties.result) {
Expand All @@ -34,7 +33,8 @@ var cleaveReactClass = CreateReactClass({
}

// update phone region code
if (phoneRegionCode && phoneRegionCode !== owner.properties.phoneRegionCode) {
const prevPhoneRegionCode = (prevProps.options || {}).phoneRegionCode;
if (prevPhoneRegionCode !== phoneRegionCode && phoneRegionCode && phoneRegionCode !== owner.properties.phoneRegionCode) {
owner.properties.phoneRegionCode = phoneRegionCode;
owner.initPhoneFormatter();
owner.onInput(owner.properties.result);
Expand Down

0 comments on commit b9a9e17

Please sign in to comment.