Every time the next state is based on the existing one, better use the callback version of the state updater. Here it would be updateCarSpeed(prevCarSpeed => prevCarSpeed + 5).
I will be glad to use the callback version. Thank you for the advice. Do you mind explaining in more detail, why exactly is it better to use the callback version?
Every time the next state is based on the existing one, better use the callback version of the state updater. Here it would be
updateCarSpeed(prevCarSpeed => prevCarSpeed + 5)
.I will be glad to use the callback version. Thank you for the advice. Do you mind explaining in more detail, why exactly is it better to use the callback version?
I think it's similar to setState in the class components - you can be sure that you're updating the correct value, am I right @guico33 ?
Yes