garganurag893 / react-native-phone-number-input

React Native component for phone number.
MIT License
373 stars 216 forks source link

How to handle the validation and getCallingCode if we use multiple phoneInput in single page #105

Open praveennachi60 opened 2 years ago

praveennachi60 commented 2 years ago

Scenerio : Usually, we can validate the phonenumber & country code with help of UseRef of the phone input component. In my case, its dynamic based on the user selection, it will create a number of phoneInput boxes. That time, if the user changed different country code and number means it is validating with last changed countrycode with other phone number.

Problem faced: isvalidNumber & getcallingcode not properly working if multiple phone input boxes.

Expecting:

  1. how to solve by using multiple useref? or
  2. Any suggestion to validate and get the calling code?

image

maxmturner commented 1 year ago

I have handled this by putting React-Native-Phone-Number-Input within a component with it's own refs and state. Then you can dynamically render multiple of those parent components.