cpvdeveloper / use-omise

A React hook for Omise.js debit/credit card payments 💳
MIT License
8 stars 4 forks source link

useOmise hook doesn't return CreateTokenFunction. #7

Open geeorgipehlianov1 opened 1 year ago

geeorgipehlianov1 commented 1 year ago

Hello, when I try to destructure the result from useOmise hook and get the createTokenPromise function the result is null the first time, after I refresh the page few times(not specific times, sometimes 1 time, sometime 2-3-4) I get the needed result(which is the function).

Screenshot 2023-01-27 at 16 34 36 Screenshot 2023-01-27 at 16 34 47 Screenshot 2023-01-27 at 16 35 01
cpvdeveloper commented 1 year ago

@geeorgipehlianov1 this is because the Omise script is still loading, during which time you won't have access to functions such as createTokenPromise. If you also console log the loading variable returned from useOmise, you should see that it's true whilst createTokenPromise is null.

Usually this won't be a problem though, because you should only need createTokenPromise once there has been some user interaction e.g. entering credit card details, by which time the script should have loaded.

geeorgipehlianov1 commented 1 year ago

@cpvdeveloper I see that the script is still loading I have also logged the loading variable but the loading stays true and noting is changed until I make some change on the component or refresh the page. I have build an app where the user is interacting and the problem is still the same. Interesting thing is that it worked few days ago and when I tried it on Friday the problem showed up. Because of the typescript I should add a check if(createTokenPromise) -> then do the needed logic and since the createTokenPromise remain null all the time the logic about creating a charge token is skipped.