Skip to content

Commit 3d33fe1

Browse files
committed
updated react update cycle
1 parent abf0e7f commit 3d33fe1

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,22 @@ export default class TextInputMask extends Component {
3434
}
3535
}
3636

37-
componentWillReceiveProps(nextProps) {
38-
if (nextProps.mask && (this.props.value !== nextProps.value)) {
39-
mask(this.props.mask, '' + nextProps.value, text =>
40-
this.input && this.input.setNativeProps({ text })
41-
);
37+
componentDidUpdate(prevProps, _, snapshot) {
38+
if (snapshot.mask && prevProps.value !== snapshot.value) {
39+
mask(prevProps.mask, "" + snapshot.value, text => this.input && this.input.setNativeProps({ text }));
4240
}
4341

44-
if (this.props.mask !== nextProps.mask) {
45-
setMask(findNodeHandle(this.input), nextProps.mask)
42+
if (prevProps.mask !== snapshot.mask) {
43+
setMask(findNodeHandle(this.input), snapshot.mask);
4644
}
4745
}
4846

47+
getSnapshotBeforeUpdate() {
48+
const { mask: maskValue, value } = this.props;
49+
50+
return { mask: maskValue, value };
51+
}
52+
4953
render() {
5054
return (<TextInput
5155
{...this.props}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-text-input-mask",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "Text input mask for React Native.",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)