let [myValue, setValue] = useState(30);
let k = {};
let z = {};
const a = useCallback(() => {
return myValue + 10;
}, [myValue]
)
k = a;
setTimeout(() => {
setValue(60)
}, 2000)
setTimeout(() => {
z = a;
console.log(z == k);
}, 4000)
This is my react code.
It seems like in the final setTimeout, z is k and prints true. I don't understand why..
in 2 secs, I change myValue which should cause re-rendering which should cause calling useCallback and returning different instance of a. Any idea why it's printing true in the last setTimeout ?