I have a question. I want to subtract A and B. A is data in firebase firestore. B is data in react native app. Here is my code.
const purchaseStory = async () => {
if (rabbit.rabbitAmount < price) {
console.log('impossible');
} else {
console.log('do you want to buy?');
//console.log(amount);
setRabbitAmount({
id: user.id,
price, **// is B**
});
}
};
export function setRabbitAmount({id, price}) {
return userRabbitsCollection.doc(id).update({
rabbitAmount: rabbitAmount - price, **// is A**
});
}
current state: A is 100 / B is 35 expect result: A is changed to 65 current result: NaN
what should I do if I get the expected result?
I try to change the code
export function setRabbitAmount({id, price}) {
return userRabbitsCollection.doc(id).update({
rabbitAmount: rabbitAmount - price, **// is A**
});
}
--> rabbitAmount: this.rabbitAmount-price
but the result is still NaN