If you have a counter set to 0 and call setCounter(prev => prev + 1) three times consecutively inside an event handler, what will be the value of the counter?
- 1
- 2
- 3
- 4
The value of the counter will be 3. Each call to setCounter(prev => prev + 1) increments the counter by 1 based on the previous value. Since this is done three times consecutively, the counter goes from 0 to 1, then 1 to 2, and finally 2 to 3.
Loading...
Related Quiz
- Does React support all HTML attributes?
- Stateless components in React are also known as ________ components.
- To store the previous state or props in functional components, you can use the ________ hook.
- In GraphQL, when you want to get real-time data updates, you would use a ________ instead of a regular query.
- What happens if you modify an observable outside of an action in strict mode in MobX?