In the following code:
// create state count
const [count,setCount] = useState(0)
//update state
setCount(count-1)
setCount(count-1)
The value of count decreases by one only, because setCount() is an asynchronous function. I understand this. But why does the following code work fine, i.e count is decreased by two when a function is passed instead of a statement?
setCount(prevCount => prevCount-1)
setCount(prevCOunt => prevCount-1)
Why does the same behaviour as in the first case not appear here? I have limited experience with async functions and am new to react. Thanks for reading!