In state component we can use the following idiom
state = {
count: 0
}
addCount = () => {
this.setState( prevState => ({
count: prevState.count + 1
}));
}
In react hooks, we do similar like below.
const [count, setCount] = useState(0);
const addCount = () => {
setCount(prevCount => prevCount + 1);
}
React Hook – Prev State