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

107
Views
Get notified when ref.current changes in React

Is there a way to get notified when ref.current changes in React ? Like the code below.

const ref = useRef(0);

// pseudo code
ref.addCallback((newValue)=> {
  // notified
});

ref.current = 1; // triggers the notification.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can make use of the useCallback hook like so:

const onChange = useCallback(value => {
   if(value) {
      // do whatever you want
   }
}, []);

And pass the function to the ref ref prop:

<div ref={onChange}></div>

Note that this does not trigger rerendes yet. You would need to set value to a state.

about 4 years ago · Santiago Trujillo Report

0

You can use a library like Observable Slim

Here is an example of how you would use it:

ObservableSlim.create(ref.current, true, function(changes) {
    console.log(JSON.stringify(changes));
});
about 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!