React Quiz on how useState works 1/2 
Q: If we call the `increment` function once, what will be the value of `counter` in the next render?
Choose your answer using the poll in the thread!
#reactjs #CodeNewbie #100DaysOfCode #javascript #CodeNewbies
...

Q: If we call the `increment` function once, what will be the value of `counter` in the next render?
Choose your answer using the poll in the thread!
#reactjs #CodeNewbie #100DaysOfCode #javascript #CodeNewbies
...


The answer can be found in this CodeSandbox
https://codesandbox.io/s/counter-1-gjvzt?file=/src/App.js
But wait, don't leave, there's still another question

But wait, don't leave, there's still another question

React Quiz on how useState works 2/2 
Same question but different code! What will happen now?
Q: If we call the `increment` function once, what will be the value of `counter` in the next render?

Same question but different code! What will happen now?
Q: If we call the `increment` function once, what will be the value of `counter` in the next render?

The answer can be found in this CodeSandbox
https://codesandbox.io/s/counter-2-5spji?file=/src/App.js
...

...
If you don't understand what's going on it's probably because you just need to learn how `useState` works, and for that I'm going to recommend you this article:
https://kentcdodds.com/blog/use-state-lazy-initialization-and-function-updates
By @kentcdodds


Hope you liked it!
Follow me if you want to learn more about React, JavaScript or the web in general
Follow me if you want to learn more about React, JavaScript or the web in general

You may also want to check out this schema to see what's going on with these setCounter calls 
Built with @excalidraw

Built with @excalidraw