79132010

Date: 2024-10-28 03:54:09
Score: 1.5
Natty:
Report link

As I understand the problem you are having, you are misunderstanding how useState works.

Simply put, when you setState it will be asynchronous, and when you log right below setState it will not have the new value immediately, you will only get the new value when the component re-renders after setState.

There are 2 ways for you to log the new value immediately:

Reasons:
  • No code block (0.5):
  • Low reputation (1):
Posted by: haiquan0121