UNPKG

react-grecaptcha-v3

Version:

Google Recaptcha V3 for React.js based application. Keep website performance high while prioritizing security.

23 lines (22 loc) 913 B
import { key } from './global/globals'; export const getScriptSrc = ({ enterprise, useRecaptchaNet, siteKey, }) => { const hostname = useRecaptchaNet ? 'recaptcha.net' : 'www.google.com'; if (enterprise) { return `https://${hostname}/recaptcha/enterprise.js?render=${siteKey}&onload=${key}`; } return `https://${hostname}/recaptcha/api.js?render=${siteKey}&onload=${key}`; }; export const maybeInjectScript = ({ appendTo, ...scriptProps }) => { let el = document.querySelector(`script[id=${scriptProps.id}]`); if (el === null) { el = document.createElement('script'); } Object.assign(el, scriptProps); (appendTo === 'head' ? document.head : document.body).appendChild(el); }; export const maybeRemoveScript = (scriptId) => { const el = document.querySelector(`script[id=${scriptId}]`); if (null !== el) { document.head.removeChild(el); } };