I have a ReactJS file where at the top I have one of my props defined as
const [items, setItems] = useState(0);
This updates a value I show on the screen properly, and when I read the value of items
in some functions, I do get the proper value of items
. However, on one specific function with the prototype of const updateCart = (client) => {}
, when I try to get the value of items
, I get the default value defined in the useState(0);
. I do understand that props do not always update instantly, but even after reading the value correctly in another function, when I try to read it in the updateCart()
function I always get the default value, not the current value. How can I read the current value in my updateCart()
function?
Thank you