use-state-with-callback
use-state-with-callback copied to clipboard
useStateWithCallbackLazy - callback is not returned after state update complete
State has been updated but inside the callback I am getting the old value of component.
const [count, setCount] = useStateWithCallbackLazy(0);
const handleClick = () => {
setCount(count + 1, (currentCount) => {
console.log('current count value - ' + count);
});
};
The same question has been updated in stackoverflow: https://stackoverflow.com/questions/74442587/getting-state-old-value-on-react-custom-hook-callback#74442942