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

164
Views
Reaccionar: las propiedades expuestas de useImperativeHandle se superponen

Estoy creando un componente "UsernameInput", que representa mi componente personalizado "TextInput":

 const UsernameInput = forwardRef( ( { ... }, ref ) => { ... return <TextInput ref={ref} /> });

Mi componente TextInput expone algunas funciones a sus padres:

 const TextInput = forwardRef( ( { ... }, ref ) => { ... useImperativeHandle( ref, () => ({ getText: () => text, setText, focus, blur, }), [text] ); ... });

Ahora... en mi componente UsernameInput, también quiero exponer otras funcionalidades...

 const UsernameInput = forwardRef( ( { ... }, ref ) => { ... useImperativeHandle( ref, () => ({ getUsernameInformation: () => usernameInformation, }), [usernameInformation] ); return <TextInput ref={ref} /> });

El principal problema que estoy experimentando es que, si hago lo siguiente:

 const usernameInputRef = useRef(null); const handleOnSubmit = () => { usernameInputRef.current.blur() } return ( <UsernameInput ref={usernameInputRef} ... );

El código me arroja una excepción ".blur() no está definido".

Parece que, al tener dos useImperativeHandle , las funcionalidades expuestas se superponen.

¿Alguna idea sobre cómo resolver este problema?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Basado en el comentario de @Amila Senadheera:

 const textInputRef = useRef(null); ... useImperativeHandle( ref, () => ({ getUsernameInformation: () => usernameInformation, ...textInputRef.current, }), [usernameInformation] ); ... return <TextInput ref={textInputRef} ... />
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!