Happy new year all, I am struggling a bit with something which I think should be really trivial. I am trying to update a react state using setState but onPress the string does not update straight away instead it updates when I press the second time. Like I said this I think seems like a little issue but maybe a second eye would prove useful.
Below is my code:
const [selection, setSelection] = useState('');
<TouchableOpacity
onPress={() => {
setSelection(() => 'amount');
console.log(selection);
}}>
<Text>By Amount</Text>
</TouchableOpacity>
I have read in different places about useState being asynchronous and it acts as a queue, meaning the initial value would always return, but I really need the state variable to update to the string 'amount'.
Thank you in advance