return token promise by recaptcha.execute#9
return token promise by recaptcha.execute#9f1qwase wants to merge 1 commit intoszchenghuang:masterfrom
Conversation
|
I like the idea. However, the callback will be executed twice when reCAPTCHA is resolved successfully, wouldn't it? |
|
to avoid this I just pass the 'noop function' as an <Recaptcha
ref={_ => this.recaptcha = _}
sitekey='***'
onResolved={() => null}
/>it is not very nice but doesn't break old API |
|
Please do. I do like the idea. I will follow up after your update. Thanks. |
TL;DRThis promise is not a good idea due to Google reCAPTCHA's lack of an error callback, which would provide the only proper mechanism for promise rejection. Without it, we risk forever-pending promises. An alternate, non-prop means of assigning If As an alternative, you can dip your toes in callback hell and add an class GoogleRecaptcha extends Component {
...
componentDidMount() {
...
this.onResolved = action => window[this.callbackName] = action;
...
}
...
}And in your validation & submission flow, something like this: const submitArgs = [foo, bar, baz];
if (googleRecaptchaRef) {
googleRecaptchaRef.onResolved(() => {
submit(...submitArgs, googleRecaptcha);
});
googleRecaptcha.execute();
}
else {
submit(...submitArgs);
}
function submit(foo, bar, baz, googleRecaptcha) {
...
const googleRecaptchaResponse = googleRecaptcha && googleRecaptcha.getResponse();
...
} |
|
@Palisand, you make a valid point. Your comment is visionary. I do hesitate regarding the possible pending promise. I tend not to make a merge with a heuristic. Sorry for the late response. |
885a65a to
9c7f8cb
Compare
after this changes you can use recaptcha.execute this way:
so you dont't need
onResolvedandgetResponsemethods