Skip to content Skip to sidebar Skip to footer

Why Do I Have Two Different Values On This Boolean In React Native?

In the React Native App, after I click the toggle button, the function _toggleServerSwitch gets triggered. Then I change the state serverSwitchValue to the same value as x. Expecte

Solution 1:

setServerSwitchValue() is an async function , so it doesnt imply that you will get the values updated instantly. YOu can use useEffect as below :

useEffect(() => {
 console.log(serverSwitchValue);
}, [serverSwitchValue]); // Only re-run the effect if open changes

Hope it helps.

Post a Comment for "Why Do I Have Two Different Values On This Boolean In React Native?"