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

233
Views
¿Cómo configurar el código de país automáticamente por región en reaccionar?

en este código de país de número de teléfono, ¿cómo es posible configurar automáticamente el código de país por región? como si abro el sitio web en EE. UU., muestra el código de país +1 automáticamente, si abro el sitio web en INDIA, muestra el código de país +91 automáticamente. Al igual que la API meteorológica, ¿hay alguna API que deba verificar automáticamente el código de país?

 import React from "react"; import PhoneInput, {isValidPhoneNumber } from "react-phone-number-input"; export default function App() { const [fields, setFields] = React.useState([{ value: null }]); function handleChange(i, event) { if (event) { const values = [...fields]; values[i].value = event; setFields((v) => values); } } return ( <div className="App"> {fields.map((field, idx) => ( <PhoneInput key={idx} id="phoneNumbers1" type="text" placeholder="Enter phone number " value={field.value || ""} defaultCountry="IN" international name="phoneNumbers" autoComplete="off" onChange={(e) => handleChange(idx, e)} /> ))} <button type="button" > Phone Number </button> </div> ); }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Para detectar el país, la aplicación React necesita buscar la dirección IP utilizando servicios IP-to-Location como IPRegistry

Aquí hay un ejemplo del lado del cliente con IPRegistry:

 const getCountryBtn = document.getElementById("getCountry"); const countryNameElement = document.getElementById("country"); getCountryBtn.onclick = function() { fetch('https://api.ipregistry.co/?key=tryout') .then(function (response) { return response.json(); }) .then(function (payload) { countryNameElement.innerHTML = payload.location.country.name; }); }
 <html> <body> <button id="getCountry">Get Country</button> <div id="country"></div> </body> </html>

Una vez que el nombre del país está disponible, su código de país correspondiente se puede establecer como valor predeterminado en el componente React.

about 4 years ago · Santiago Trujillo 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!