Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Detecting country code for react-native-phone-number

I use the react-native-phone-number-input library. I want the country flag to be determined automatically depending on where I'm from. How do I implement this?

<PhoneInput
  ref={phoneInput}
  defaultValue={value}
  // defaultCode="DM"
  layout="first"
  // onChangeText={(v) => setValue(v)}
  onChangeFormattedText={(v) => setValue(v)}
  placeholder={' '}
  defaultCode="IN"
  withDarkTheme
  withShadow
  autoFocus
  containerStyle={{
    borderRadius: 0,
    width: '100%',
    height: 49,
  }}
  textInputStyle={{height: 68}}
  textContainerStyle={{paddingTop: 15}}
/>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you can set default country based on IP , hit API Geolocation which return countrycode or something. then return to your apps

about 4 years ago · Juan Pablo Isaza Report

0

The react-native-localize package can be used to get the country code of the current users device - and I assume this can just then be passed in to your PhoneNumber component to display the correct country flag.

import * as RNLocalize from "react-native-localize";

console.log(RNLocalize.getCountry());
// -> "FR"

I assume this would then work

<PhoneInput
  ref={phoneInput}
  defaultValue={value}
  // defaultCode="DM"
  layout="first"
  // onChangeText={(v) => setValue(v)}
  onChangeFormattedText={(v) => setValue(v)}
  placeholder={' '}
  defaultCode={RNLocalize.getCountry()}
  withDarkTheme
  withShadow
  autoFocus
  containerStyle={{
    borderRadius: 0,
    width: '100%',
    height: 49,
  }}
  textInputStyle={{height: 68}}
  textContainerStyle={{paddingTop: 15}}
/>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!