'use client'; import { useCallback, useMemo, useRef, useState } from 'react'; import type { TurnstileInstance } from '@marsidev/react-turnstile'; import { CaptchaField } from './captcha-field'; /** * @name useCaptcha * @description Zero-boilerplate hook for captcha integration. * Manages token state and instance internally, exposing a clean API. * * @example * ```tsx * function SignInForm({ captchaSiteKey }) { * const captcha = useCaptcha({ siteKey: captchaSiteKey }); * * const handleSubmit = async (data) => { * await signIn({ ...data, captchaToken: captcha.token }); * captcha.reset(); * }; * * return ( *
* ); * } * ``` */ export function useCaptcha( { siteKey, nonce }: { siteKey?: string; nonce?: string } = { siteKey: undefined, nonce: undefined, }, ) { const [token, setToken] = useState(''); const instanceRef = useRef