React Hook for Google reCAPTCHA V3
https://www.google.com/recaptcha/intro/v3.html
Install
npm install react-google-recaptcha-hook
Simplest Example
import { useGoogleReCaptcha } from "react-google-recaptcha-hook";
const Form = () => {
const { executeGoogleReCaptcha } = useGoogleReCaptcha(SITE_KEY);
const submit = useCallback(async () => {
const token = await executeRecaptcha("submit");
}, []);
return <button onClick={submit}>SUBMIT</button>;
};
Usage
const {
executeGoogleReCaptcha,
showGoogleReCaptcha,
hideGoogleReCaptcha,
} = useGoogleReCaptcha(
`${YOUR_SITE_KEY}`,
{
hide: `${BOOLEAN}`,
language: `${LANGUAGE_CODE}`,
enterprise: `${BOOLEAN}`,
recaptchaNet: `${BOOLEAN}`,
}
);
Note
You are allowed to hide the badge as long as you include the reCAPTCHA branding visibly in the user flow.
See: https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed