React Hook for Google reCAPTCHA V3
https://www.google.com/recaptcha/intro/v3.html
Features
- ⚛ React 18 support
- ✨ Simple and Easy
- 🦋 Lightweight
- 🟢 Zero dependencies
- ⬇️ Asynchronous APIs
Install
npm install react-google-recaptcha-hook
Simplest Example
import { useGoogleReCaptcha } from "react-google-recaptcha-hook";
const FormComponent = () => {
const { executeGoogleReCaptcha } = useGoogleReCaptcha(SITE_KEY);
const submit = async () => {
const token = await executeRecaptcha(ACTION_NAME);
};
return <button onClick={submit}>SUBMIT</button>;
};
Usage
const {
executeGoogleReCaptcha,
hideGoogleReCaptcha,
showGoogleReCaptcha,
} = 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