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

173
Views
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 answers
Answer question

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 Report

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 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!