Skip to content
Advertisement

Cant Update my state using setstate for paypal paiment

So my problem is that i update my state but when i try to use it to approuve my payment the OrderUrl is empty i undestard that setState is asynchrone but how can i avoid this case and update my state immediately.

i have this problem like in two or three page in my website, and i already did some searches some dudes say that i can use useEeffect to update my state by i can’t use it in my case.

JavaScript

Advertisement

Answer

You can use your onApprove handler in the PayPalButtons component to set some state and then call your approuve function from inside a useEffect hook that depends on it:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement