mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
21 lines
541 B
TypeScript
21 lines
541 B
TypeScript
import { useRef } from 'react'
|
|
import type ReCAPTCHA from 'react-google-recaptcha'
|
|
|
|
export const useRecaptcha = () => {
|
|
const ref = useRef<ReCAPTCHA | null>(null)
|
|
|
|
const getReCaptchaToken = async (): Promise<
|
|
ReturnType<ReCAPTCHA['executeAsync']>
|
|
> => {
|
|
if (!ref.current) {
|
|
return null
|
|
}
|
|
// Reset the reCAPTCHA before each submission.
|
|
// The reCAPTCHA token is meant to be used once per validation
|
|
ref.current.reset()
|
|
return await ref.current.executeAsync()
|
|
}
|
|
|
|
return { ref, getReCaptchaToken }
|
|
}
|