useDebounceCallback hook explained
Introduction
In my last side project, I needed to debounce a callback. I ended up writing a custom hook to do so. In this post, I'll explain how it works. The tricky part is grasping why we need the callback ref.
import { useCallback, useEffect, useR...
tigerabrodi.blog4 min read
rameztayem
let x = 1; const fn = () => console.log(x); // Captures x=1 x = 2; setTimeout(fn, 1000); // Will print 1, not 2
this will print 2 not 1 i have tried it any explaination why?