Hi Im trying to implement openpay services to my react native app but when i try to generate the TokenID from the credit card info i got problems with the use effect
this is the code
useEffect(() => {
let isCancelled = false;
if (vCardNameOwner && vCardNumber && vCardExpirationMonth && vCardExpirationYears && vCardCVV) {
openpay.createCardToken({
holder_name: vCardNameOwner,
card_number: vCardNumber,
expiration_month: vCardExpirationMonth,
expiration_year: vCardExpirationYears,
cvv2: vCardCVV,
})
.then((token) => setvTokenId(token), console.log( '/////generacion de token//////' ,token));
}
return () => {
isCancelled = true;
};
}, [vCardNameOwner, vCardNumber, vCardExpirationMonth, vCardExpirationYears, vCardCVV]);
that code makes my app to crash because token isnt declared and i dont know how to re do the operation so it can work fine
if i delete the useeffect thing and leave just the openpay function with hardcoded values everything work well but i need it to take the values that the user insert in the form
openpay.createCardToken({
holder_name: vCardNameOwner,
card_number: vCardNumber,
expiration_month: vCardExpirationMonth,
expiration_year: vCardExpirationYears,
cvv2: vCardCVV,
})
.then((token) => setvTokenId(token), console.log( '/////generacion de token//////' ,token));
thanks a lot for your time
question from:
https://stackoverflow.com/questions/65889636/passing-my-function-to-useeffect-crashes-my-app 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…