I have this code below:
const [clientID, setClientID] = useState({});
// explodeClientID is an object
let explodeClientID = ClientIDFormatter(routeParams.QRData);
// I assign that variable to me clientID state:
setClientID(explodeClientID);
// I logged the variable:
console.log("Exploded Client ID:")
console.log(explodeClientID);
/* OUTPUT:
Exploded Client ID:
Object {
"BR_ID": 1,
"ClientChkID": 4,
"ClientID": 599920,
} */
// I logged the state:
console.log("Client ID: ");
console.log(clientID);
/* OUTPUT
Client ID:
Object {}
*/
As you can see, the main problem is that when I assign explodeClientID
to a regular variable, it has value. But when I use setState
to update, it still returns an empty object. This shouldn't be an issue at all since it's not an API call that I need to await.