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

With jQuery, how to automatically select the value of an input text that has been modified with the arrows? With jQuery, how to automatically select the value of an input text that has been modified with the arrows?

Cannot create an instance of a defined class in Javascript Cannot create an instance of a defined class in Javascript

Using Ts-Standard linting, JSDoc comment at beginning of file triggers "This rule requires the `strictNullChecks` compiler option" error Using Ts-Standard linting, JSDoc comment at beginning of file triggers "This rule requires the `strictNullChecks` compiler option" error