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

136
Views
useRef da indefinido en React Native pero no en React

Estoy tratando de aplicar una máscara para mi entrada, estoy usando useRef para obtener el valor actual, pero siempre regresa indefinido, me encuentro con un error, probé el mismo código en React cambiando solo la entrada a TextInput , y está funcionando. Aquí está mi código

 const [card, setCard] = useState(); const inputCard = useRef(); const handleChange = () => { const cardValue = inputCard.current.value .replace(/\D/g, "") .match(/(\d{0,4})(\d{0,4})(\d{0,4})(\d{0,4})/); inputCard.current.value = !cardValue[2] ? cardValue[1] : `${cardValue[1]}-${cardValue[2]}${`${cardValue[3] ? `-${cardValue[3]}` : ""}`}${`${ cardValue[4] ? `-${cardValue[4]}` : "" }`}`; const numbers = inputCard.current.value.replace(/(\D)/g, ""); setCard(numbers); }; useEffect(() => { handleChange(); }, [card]);

y finalmente esta es la entrada para React Native

 <TextInput keyboardType='number-pad' ref={inputCard} onChangeText={handleChange} />

y esta es la entrada para React

 <input ref={inputCard} onChange={handleChange} />

y este es el error que estoy recibiendo en React Native

 TypeError: undefined is not an object (evaluating 'inputCard.current.value.replace')
about 4 years ago · Juan Pablo Isaza
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!