в форме:
import React, { useState } from 'react';
import { useReCaptcha } from 'react-use-recaptcha-v3';
const ControlledGoogleReCaptcha = () => {
const [token, setToken] = useState();
const handleToken = (tokenFromGoogleResponse) => {
console.log('fresh token is appear here, each time actionName is changed', { tokenFromGoogleResponse });
setToken(tokenFromGoogleResponse);
};
const siteKey = '[SET UP YOU SITE KEY HERE!!!]';
const actionName = 'submit'; // you can change actionName here if you need
useReCaptcha(siteKey, handleToken, actionName);
return (
<form>
{/* other fields here */}
{token ? <input name="g-recaptcha" value={token} /> : null}
</form>
);
};
verifyCallback = (recaptchaToken) => { // Here you will get the final recaptchaToken!!! console.log(recaptchaToken, "<= your recaptcha token") } <ReCaptcha sitekey="your_site_key" action='action_name' verifyCallback={this.verifyCallback} />
Для v3 не нужно в dom внедрять.
Обсуждают сегодня