Do you have a reduced code sample? I can’t quite picture the stale state issue.
(I suppose this is a good example in favour of the opposing “useCallback is premature optimisation” opinion)
(I suppose this is a good example in favour of the opposing “useCallback is premature optimisation” opinion)
https://codepen.io/rodeoclash/pen/poLqeYb?editors=1111
Even though `theState` is passed to the dependency array of the parent component which is tracking hidden images, it will still be stale!
After a while, I figured out that the child components, where the click originates from, also needed to have the map of deleted images passed to their dependency array. Total footgun.