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

240
Views
¿Cómo puedo usar forwardRef() en React?

Actualmente recibo el siguiente error en mi aplicación React:

A los componentes de función no se les pueden dar refs. Los intentos de acceder a esta referencia fallarán. ¿Querías usar React.forwardRef()?

¿Cómo puedo arreglar esto usando forwardRef()?

Mi código es el siguiente:

 const Services: FunctionComponent = (): ReactElement => { const servicesRef = useRef(null); return ( <Layout> <ServicesList ref={servicesRef} /> </Layout> ); }; export default Services; const ServicesList: React.FunctionComponent = ({ children }: Props) => { return ( <section className="my-24 md:my-32"> {children && children} </section> ); }; export default ServicesList;
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

function Parent(){ const childRef = React.useRef(null) // do something with your childRef React.useEffect(()=> { childREf.current.focus() },[]) return( <div> <Child ref={childRef} /> </div>) } const Child = React.forwardRef((props, ref) => { console.log(ref.current) return( <div tabIndex={1} ref={ref}> child </div) })
over 4 years ago · Santiago Trujillo Report

0

Los documentos de reacción explican bien ...

https://reactjs.org/docs/forwarding-refs.html

Envuelva su componente con React.forwardRef y establezca la referencia en el elemento DOM deseado

 const FancyButton = React.forwardRef((props,ref)=>( <buttonref={ref} className="FancyButton"> {props.children} </button>) );
over 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!