Introduction
Callback functions help update state based on the previous state safely. They avoid mistakes when many updates happen quickly.
When you want to increase a counter based on its current value.
When you need to toggle a boolean state like showing or hiding a menu.
When multiple state updates happen fast and you want to avoid wrong values.
When your new state depends on the old state value.
When you want to ensure state updates happen in the right order.