
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
react-enterprise-recaptcha
Advanced tools
A lightweight React wrapper for reCAPTCHA Enterprise with a next-recaptcha-v3–compatible API. Pure client-side, framework-agnostic.
A lightweight reCAPTCHA Enterprise wrapper for React with a next-recaptcha-v3–compatible API. Framework-agnostic (no Next.js dependency) and client-only.
ReCaptchaProvider — loads the Enterprise script and provides contextuseReCaptcha() — returns { executeRecaptcha(action?), isLoaded, isError, error, defaultAction }<ReCaptcha /> — convenience component that runs on mount / when refreshReCaptcha changeswithReCaptcha() — HOC that injects { isLoaded, executeRecaptcha }NEXT_PUBLIC_RECAPTCHA_ACTION / RECAPTCHA_ACTION)https://www.google.com/recaptcha/enterprise.js)⚠️ This library targets reCAPTCHA Enterprise. It does not load or polyfill the non-Enterprise API.
npm i react-enterprise-recaptcha
# or
yarn add react-enterprise-recaptcha
# or
pnpm add react-enterprise-recaptcha
Peer deps: React ≥ 17
import { ReCaptchaProvider, useReCaptcha, ReCaptcha } from "react-enterprise-recaptcha";
function App() {
return (
<ReCaptchaProvider
reCaptchaKey={process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY}
language="en"
defaultAction="login" // used when executeRecaptcha() is called without an action
>
<Login />
</ReCaptchaProvider>
);
}
function Login() {
const { executeRecaptcha } = useReCaptcha();
const onSubmit = async (e: React.FormEvent) => {
e.preventDefault();
// Uses provider's defaultAction ("login")
const token = await executeRecaptcha();
await fetch("/api/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token }),
});
};
return <form onSubmit={onSubmit}>{/* ... */}</form>;
}
// Optional convenience component:
function PageView() {
return (
<ReCaptcha
action="page_view"
onValidate={(token) => console.log(token)}
refreshReCaptcha={Date.now()} // re-run when this value changes
/>
);
}
<ReCaptchaProvider />Wrap your app with the provider. It injects the Enterprise script and exposes context.
| Prop | Type | Default | Description |
|---|---|---|---|
reCaptchaKey | string | — | Your Enterprise site key |
language | string | — | UI language (e.g. "en", "ja") |
useRecaptchaNet | boolean | false | Load from recaptcha.net (e.g. mainland China) |
nonce | string | — | CSP nonce for the injected <script> |
defaultAction | string | — | Default action for executeRecaptcha() |
reCaptchaAction | string | — | Alias of defaultAction (naming parity) |
useEnterprise | boolean | true | Kept for API compatibility; always treated as Enterprise |
Environment variables (used if props are not provided):
NEXT_PUBLIC_RECAPTCHA_SITE_KEYNEXT_PUBLIC_RECAPTCHA_ACTION or RECAPTCHA_ACTIONPriority: props > NEXT_PUBLIC_RECAPTCHA_ACTION > RECAPTCHA_ACTION.
useReCaptcha()Hook that gives you access to the context.
type UseReCaptcha = () => {
reCaptchaKey?: string;
grecaptcha?: any; // raw global for advanced usage
isLoaded: boolean;
isError: boolean;
error: Error | null;
defaultAction?: string;
executeRecaptcha: (action?: string) => Promise<string>;
};
executeRecaptcha(action?): If action is omitted, the provider’s defaultAction (or env) is used.<ReCaptcha /> (optional)Convenience component that executes on mount and when refreshReCaptcha changes, calling onValidate(token).
| Prop | Type | Required | Description |
|---|---|---|---|
onValidate | (token: string) => void | ✔︎ | Receives the token |
action | string | — | Uses provider default if omitted |
refreshReCaptcha | any | — | Re-executes when this value changes |
onError | (err: unknown) => void | — | Called on failure |
withReCaptcha(Component)Higher-order component that injects { isLoaded, executeRecaptcha(action?) } into your component.
import { withReCaptcha } from "react-enterprise-recaptcha";
function VerifyButton({ isLoaded, executeRecaptcha }: {
isLoaded: boolean; executeRecaptcha: (a?: string) => Promise<string>;
}) {
return (
<button
disabled={!isLoaded}
onClick={async () => {
const token = await executeRecaptcha("button_click");
console.log(token);
}}
>
Verify
</button>
);
}
export default withReCaptcha(VerifyButton);
Window.grecaptcha typings.nonce and recaptcha.net host.executeRecaptcha() can omit the action.Invalid hook call / multiple Reacts: Ensure your app uses a single React instance.
Package is published with react/react-dom as peerDependencies (not bundled).
If you are linking locally, prefer npm pack + install the .tgz instead of npm link.
Optionally force a single React via bundler:
Webpack/Rspack:
resolve: { alias: {
react: path.resolve(__dirname, 'node_modules/react'),
'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
}}
Vite: resolve: { dedupe: ['react','react-dom'] }
Props mutation errors (e.g., “object is not extensible”): Never mutate incoming props; clone/derive new objects when needed.
Enterprise vs non-Enterprise: This library only loads the Enterprise script. Make sure your site key is an Enterprise key.
MIT
FAQs
A lightweight React wrapper for reCAPTCHA Enterprise with a next-recaptcha-v3–compatible API. Pure client-side, framework-agnostic.
The npm package react-enterprise-recaptcha receives a total of 18 weekly downloads. As such, react-enterprise-recaptcha popularity was classified as not popular.
We found that react-enterprise-recaptcha demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.