score:1

Accepted answer

depending on how getvalidationresponse is used, i suspect there might be a issue with closure that captures validationcount as 0 resulting the updated value to be 1 always.

try using functional updates which will update the value of validationcount based on the previous value.

setvalidationcount(prevcount => prevcount + 1);

score:0

it's a closure problem, you can see it in action here, basically, if you click on it slowly, it works fine, if you click on it multiple times before the previous update is concluded, you create functions where validationcount still hasn't updated. it's always good to remember that setstate is an async function.


Related Query

More Query from same tag