react js useState array is empty in first time click in the console log react js useState array is empty in first time click in the console log

Please check my below code. I try to check the console log value, but in the first button click, the array is empty. After the second click the array will be loaded correctly.

Please check this:

sample

The above sample can be found on Google. I console log the value as below enter image description here

Why is the array empty in the first click? Another question is, I need to print the value in the first click. How can I do it? Do you know any alternative method?



from Stackoverflow

Comments

Popular posts from this blog

How to extract items from a subarray and push them to the main array

Detox gets stuck on JS Timer/Main Run Loop when registering a lot of screens with React Native Navigation Detox gets stuck on JS Timer/Main Run Loop when registering a lot of screens with React Native Navigation

\\u0000 cannot be converted to text error \\u0000 cannot be converted to text error