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

174
Views
No se puede acceder a Ref desde useEffect usando "this.refname.current"

Me falta algo simple aquí, necesito acceder a una Ref definida dentro de un useEffect . El depurador muestra que this no está definido y, por lo tanto, no puedo hacer this.refOverlay.current; .

 // Ref const refOverlay = useRef(null); // Sample useEffect that references it useEffect(() => { if (props.mode === 'new') { let b = this; // Undefined let a = this.refOverlay.current; // Error on this line if (a) { console.log('ok'); } } }, [props.mode]); ... return ( {/* JSX Definition */} <OverlayTrigger ref={refOverlay} trigger="click" rootClose placement="bottom" overlay={popoverApprover}> <a href="javascript:void(0)" className="more-info">TEST</a> </OverlayTrigger> );
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Ha definido un componente basado en funciones. Que no tiene la palabra clave this Simplemente elimine la palabra clave this y estará bien.

about 4 years ago · Juan Pablo Isaza Report

0

No hay tal this en el componente de función.

 const Title = () => { const ref = useRef(null) useEffect(() => { if (ref.current) { ref.current.WHATEVERYOUWANTHERE } }, []) }

NOTA: un par de diferencias entre la clase y el componente de función

  • componente de función no tiene esto, es una función
  • componente de la función es sólo la función de representación
  • para tener estado, necesitas useState
  • para tener cualquier almacenamiento persistente, necesita gancho
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!