Skip to content
recaptcha-next

Client API

Everything in recaptcha-next/client. These run in the browser, in Client Components.

RecaptchaField

Renders a hidden input and keeps a fresh token in it.

PropDefaultDescription
actionrequiredAction name. Check the same name on the server.
siteKeyNEXT_PUBLIC_RECAPTCHA_SITE_KEYPublic site key. Without a key the field renders nothing.
nameg-recaptcha-responseName of the hidden input.
lazyfalseLoad Google’s script only when the form is near the viewport.
lazyRootMargin200pxHow early lazy loading starts.
refreshIntervalMs90000Time between token refreshes. Google tokens last two minutes.
onTokenGeneratedCalled with each new token. Inline functions are safe.
onErrorCalled when the script fails to load or a token cannot be made.

useRecaptcha

const { status, error, execute } = useRecaptcha({ action: "contact" });

Options are action, siteKey and enabled. It returns:

ValueDescription
statusidle, loading, ready or error.
errorThe error when the status is error, otherwise null.
executeReturns a promise of a fresh token. Call it when the user submits the form.

Use it when you build the FormData yourself. See Custom FormData.