📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP

react-google-recaptcha-v3

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-google-recaptcha-v3

React component for google-recaptcha v3

1.10.1
latest
Version published
Maintainers
1
Created

What is react-google-recaptcha-v3?

The react-google-recaptcha-v3 npm package is a React component wrapper for Google reCAPTCHA v3, which helps protect your website from spam and abuse while letting real users pass through with ease. It provides a simple way to integrate Google reCAPTCHA v3 into your React applications.

What are react-google-recaptcha-v3's main functionalities?

Loading reCAPTCHA

This code demonstrates how to load the Google reCAPTCHA v3 script by wrapping your application with the GoogleReCaptchaProvider component and providing your reCAPTCHA site key.

import React from 'react';
import { GoogleReCaptchaProvider } from 'react-google-recaptcha-v3';

const App = () => (
  <GoogleReCaptchaProvider reCaptchaKey="your-recaptcha-key">
    <YourComponent />
  </GoogleReCaptchaProvider>
);

export default App;

Executing reCAPTCHA

This code demonstrates how to execute the reCAPTCHA verification process within a component using the useGoogleReCaptcha hook. The executeRecaptcha function is called to get the reCAPTCHA token.

import React, { useEffect } from 'react';
import { useGoogleReCaptcha } from 'react-google-recaptcha-v3';

const YourComponent = () => {
  const { executeRecaptcha } = useGoogleReCaptcha();

  useEffect(() => {
    const handleReCaptchaVerify = async () => {
      if (!executeRecaptcha) {
        console.log('Execute recaptcha not yet available');
        return;
      }
      const token = await executeRecaptcha('homepage');
      console.log(token);
    };

    handleReCaptchaVerify();
  }, [executeRecaptcha]);

  return <div>Your Component</div>;
};

export default YourComponent;

Other packages similar to react-google-recaptcha-v3

FAQs

Package last updated on 10 Dec 2022

Did you know?

Socket

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.

Install

Related posts