15. State change maintain previous state - florypaul/ReactJS GitHub Wiki
During state management - always remember to call the previous State if the state update depends on the previous state change
example
function App { // state const [showPara, setShowPara] = useState(false); // initial state is false
// on button click we are changing state to true, but here previous state dependency is there const ToggleParaHandler= () => { setShowPara(true) }
so we write the code to let react know that there is a change in the previous state const toggleHander = () =>{ setShowPara((prevShowPara) => !prevShowPara);
}
}