DEV Community

Discussion on: How to use React Hooks to create a Counter Component

Collapse
 
zingitdev profile image
zinGit-Dev

hello, please, if you can explain, would like to know why
setCount(prevCount => prevCount + 1) and not setCount( count + 1)
pd: amazing post

Collapse
 
dayoolacodes profile image
Dayo Ayoola

setState in the react useState hooks can also take a callback function which has the previous value of that particular state. so you can update the previous value to whatever you want.