Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
Can't access Ref from useEffect using "this.refname.current"

I'm missing something simple here, I need to access a defined Ref within a useEffect . The debugger shows that this is undefined and therefore I can't do 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 Respuestas
Responde la pregunta

0

You have defined a functional based component. Which doesn't have the this Simply remove the this keyword and you're fine.

about 4 years ago · Juan Pablo Isaza Denunciar

0

There's no such this in the function component.

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

NOTE: couple of difference between class and function component

  • function component has no this, it's a function
  • function component is only the render function
  • to have state, you need useState
  • to have any persistent storage, you need hook
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda