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

176
Views
¿Es posible pasar una identificación/cadena a un evento onFocus?

¿Es posible pasar la clave/ID a un evento onFocus?

Aquí está mi código:

 handleChange: (e: SyntheticEvent<FormInputElements>) => void, handleFocus: (e: SyntheticEvent<FormInputElements>) => void, const handleEvent = (event?: EventListener, inputvalue: string) => { if (event) { return event(component, inputvalue); } return null; }; const handleChange = (e: SyntheticEvent<FormInputElements>) => { handleEvent(onChange, e.currentTarget.value); if (hasFocus && showErrors) { setResolvedErrors(true); handleFocus(component.key); } }; const handleFocus = (e: SyntheticEvent<FormInputElements>) => { setHasFocus(true); handleEvent(onFocus, e.currentTarget.value); };

Básicamente, dentro de mi evento handleChange , si se ejecuta la declaración if, me gustaría ejecutar el evento handleFocus , pero pasarle la clave de mi componente, para que se centre en el elemento correcto.

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

0

Puede usar el gancho useRef para ese propósito.

Echa un vistazo al ejemplo dado:

 function TextInputWithFocusButton() { const inputEl = useRef(null); const onButtonClick = () => { // `current` points to the mounted text input element inputEl.current.focus(); }; return ( <> <input ref={inputEl} type="text" /> <button onClick={onButtonClick}>Focus the input</button> </> ); }
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!