react-native-phone-number-input
react-native-phone-number-input copied to clipboard
defaultCountryCode did not update the flag despite its value changing
Hi! π
Firstly, thanks for your work on this project! π
Today I used patch-package to patch [email protected] for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/react-native-phone-number-input/lib/index.js b/node_modules/react-native-phone-number-input/lib/index.js
index b89c388..a57a6ba 100644
--- a/node_modules/react-native-phone-number-input/lib/index.js
+++ b/node_modules/react-native-phone-number-input/lib/index.js
@@ -48,6 +48,15 @@ export default class PhoneInput extends PureComponent {
}
}
+ async componentDidUpdate(prevProps) {
+ if (prevProps.defaultCode !== this.props.defaultCode) {
+ const { defaultCode } = this.props;
+ if (defaultCode) {
+ const code = await getCallingCode(defaultCode);
+ this.setState({ code, countryCode: defaultCode });
+ }
+ }
+ }
+
getCountryCode = () => {
return this.state.countryCode;
};
This issue body was partially generated by patch-package.
Introduced componentDidUpdate to detect any changes to defaultCode that we can directly update here
Would like to make this patch into a PR here
I have this issue also the main reason is the state doesn't be updated when props change but commenting this line solves the problem but there won't be default code https://github.com/garganurag893/react-native-phone-number-input/blob/ccd16fc20d8a0a476867417279932db0e41fdb2b/lib/index.js#L21
Hi! π
Firstly, thanks for your work on this project! π
Today I used patch-package to patch
[email protected]for the project I'm working on.Here is the diff that solved my problem:
diff --git a/node_modules/react-native-phone-number-input/lib/index.js b/node_modules/react-native-phone-number-input/lib/index.js index b89c388..a57a6ba 100644 --- a/node_modules/react-native-phone-number-input/lib/index.js +++ b/node_modules/react-native-phone-number-input/lib/index.js @@ -48,6 +48,15 @@ export default class PhoneInput extends PureComponent { } } + async componentDidUpdate(prevProps) { + if (prevProps.defaultCode !== this.props.defaultCode) { + const { defaultCode } = this.props; + if (defaultCode) { + const code = await getCallingCode(defaultCode); + this.setState({ code, countryCode: defaultCode }); + } + } + } + getCountryCode = () => { return this.state.countryCode; };This issue body was partially generated by patch-package.
Bro Your code works Aweeeesooommmmeeee, Thankssssss a lotttttt
Thanks Alooot bro I was wondering and trying to achieve this Thanks alot
Thanks Alooot bro
I was wondering and trying to achieve this
Thanks alot
Glad it helped!
Would like to make it into a PR, but maybe i can just fork it into a patch