|
1 | 1 | import ReCAPTCHA from "./recaptcha";
|
2 | 2 | import makeAsyncScriptLoader from "react-async-script";
|
3 | 3 |
|
4 |
| -const callbackName = "onloadcallback"; |
5 |
| -const options = (typeof window !== "undefined" && window.recaptchaOptions) || {}; |
| 4 | +function getOptions() { |
| 5 | + return (typeof window !== "undefined" && window.recaptchaOptions) || {}; |
| 6 | +} |
| 7 | +function getURL() { |
| 8 | + const dynamicOptions = getOptions(); |
| 9 | + const lang = dynamicOptions.lang ? `&hl=${dynamicOptions.lang}` : ""; |
| 10 | + const hostname = dynamicOptions.useRecaptchaNet |
| 11 | + ? "recaptcha.net" |
| 12 | + : "www.google.com"; |
| 13 | + return `https://${hostname}/recaptcha/api.js?onload=${callbackName}&render=explicit${lang}`; |
| 14 | +} |
6 | 15 |
|
7 |
| -const lang = options.lang ? `&hl=${options.lang}` : ""; |
8 |
| -const hostname = options.useRecaptchaNet ? "recaptcha.net" : "www.google.com"; |
9 |
| -const URL = `https://${hostname}/recaptcha/api.js?onload=${callbackName}&render=explicit${lang}`; |
| 16 | +const callbackName = "onloadcallback"; |
10 | 17 | const globalName = "grecaptcha";
|
| 18 | +const initialOptions = getOptions(); |
11 | 19 |
|
12 |
| -export default makeAsyncScriptLoader(ReCAPTCHA, URL, { |
| 20 | +export default makeAsyncScriptLoader(ReCAPTCHA, getURL, { |
13 | 21 | callbackName,
|
14 | 22 | globalName,
|
15 |
| - exposeFuncs: ["getValue", "getWidgetId", "reset", "execute"], |
| 23 | + removeOnMount: initialOptions.removeOnMount || false, |
| 24 | + exposeFuncs: ["getValue", "getWidgetId", "reset", "execute"] |
16 | 25 | });
|
0 commit comments