Skip to content

Commit e368560

Browse files
authored
Remove Outdated react lifecycle components & updated the react version to 16.4.1 (patw0929#227)
* Bumping React version to 16.4.1 & removing deprecated lifecycle events
1 parent bb09300 commit e368560

File tree

8 files changed

+51
-38
lines changed

8 files changed

+51
-38
lines changed

example/0.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@
8181
"node-sass": "^4.2.0",
8282
"pre-commit": "^1.2.2",
8383
"raf": "^3.4.0",
84-
"react": "^16.2.0",
84+
"react": "^16.4.1",
8585
"react-dev-utils": "^0.4.2",
86-
"react-dom": "^16.2.0",
86+
"react-dom": "^16.4.1",
8787
"react-hot-loader": "^1.3.0",
8888
"recursive-readdir": "2.1.0",
8989
"rimraf": "2.5.4",

src/components/CountryList.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ class CountryList extends Component {
1616
this.setDropdownPosition = this.setDropdownPosition.bind(this);
1717
}
1818

19-
componentWillReceiveProps(nextProps) {
20-
if (nextProps.showDropdown) {
19+
shouldComponentUpdate(nextProps) {
20+
const shouldUpdate = !utils.shallowEquals(this.props, nextProps);
21+
22+
if (shouldUpdate && nextProps.showDropdown) {
2123
this.listElement.setAttribute('class', 'country-list v-hide');
2224
this.setDropdownPosition();
2325
}
24-
}
2526

26-
shouldComponentUpdate(nextProps) {
27-
return !utils.shallowEquals(this.props, nextProps);
27+
return shouldUpdate;
2828
}
2929

3030
setDropdownPosition() {

src/components/IntlTelInputApp.js

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ const mobileUserAgentRegexp =
1313
/Android.+Mobile|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
1414

1515
class IntlTelInputApp extends Component {
16+
17+
static getDerivedStateFromProps(nextProps, prevState) {
18+
let newState = null;
19+
20+
if (nextProps.value && prevState.value !== nextProps.value) {
21+
newState = {
22+
value: nextProps.value,
23+
};
24+
}
25+
26+
if (nextProps.disabled && prevState.disabled !== nextProps.disabled) {
27+
newState = {
28+
disabled: nextProps.disabled,
29+
};
30+
}
31+
32+
return newState;
33+
}
34+
1635
constructor(props) {
1736
super(props);
1837

@@ -152,41 +171,29 @@ class IntlTelInputApp extends Component {
152171
document.addEventListener('keydown', this.handleDocumentKeyDown);
153172
}
154173

155-
componentWillReceiveProps(nextProps) {
156-
if (this.props.value !== nextProps.value) {
157-
this.setState({
158-
value: nextProps.value,
159-
});
160-
}
161-
162-
if (this.props.disabled !== nextProps.disabled) {
163-
this.setState({
164-
disabled: nextProps.disabled,
165-
});
166-
}
167-
168-
if (
169-
typeof nextProps.customPlaceholder === 'function' &&
170-
this.props.customPlaceholder !== nextProps.customPlaceholder
171-
) {
172-
this.updatePlaceholder(nextProps);
173-
}
174-
}
175-
176-
componentWillUpdate(nextProps, nextState) {
174+
shouldComponentUpdate(nextProps, nextState) {
177175
if (nextState.showDropdown) {
178176
document.addEventListener('keydown', this.handleDocumentKeyDown);
179177
this.bindDocumentClick();
180178
} else {
181179
document.removeEventListener('keydown', this.handleDocumentKeyDown);
182180
this.unbindDocumentClick();
183181
}
182+
183+
return true;
184184
}
185185

186186
componentDidUpdate(prevProps) {
187187
if (this.props.value !== prevProps.value) {
188188
this.updateFlagFromNumber(this.props.value);
189189
}
190+
191+
if (
192+
typeof this.props.customPlaceholder === 'function' &&
193+
prevProps.customPlaceholder !== this.props.customPlaceholder
194+
) {
195+
this.updatePlaceholder(this.props);
196+
}
190197
}
191198

192199
componentWillUnmount() {

src/components/RootModal.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ class RootModal extends Component {
1010
this._render();
1111
}
1212

13-
componentWillUpdate() {
13+
shouldComponentUpdate() {
1414
this._render();
15+
16+
return false;
1517
}
1618

1719
componentWillUnmount() {

src/example.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ class DemoComponent extends Component {
3636
phone1: '',
3737
phone2: '',
3838
};
39-
}
40-
41-
componentWillMount() {
4239
this.changePhone1 = this.changeHandler.bind(this, 'phone1');
4340
this.changePhone2 = this.changeHandler.bind(this, 'phone2');
4441
this.blurHandler1 = this.blurHandler.bind(this, 'phone1');

0 commit comments

Comments
 (0)