Socket
Socket
Sign inDemoInstall

react-google-recaptcha

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-google-recaptcha

React Component Wrapper for Google reCAPTCHA


Version published
Weekly downloads
654K
decreased by-0.45%
Maintainers
1
Weekly downloads
 
Created

What is react-google-recaptcha?

The react-google-recaptcha package is a React component wrapper for Google reCAPTCHA, which helps protect websites from spam and abuse by using advanced risk analysis techniques to differentiate between humans and bots.

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

Basic reCAPTCHA Integration

This code demonstrates how to integrate Google reCAPTCHA into a React form. The `ReCAPTCHA` component is used to render the reCAPTCHA widget, and the `handleCaptchaChange` function is called whenever the reCAPTCHA value changes.

import React from 'react';
import ReCAPTCHA from 'react-google-recaptcha';

function MyForm() {
  const handleCaptchaChange = (value) => {
    console.log('Captcha value:', value);
  };

  return (
    <form>
      <ReCAPTCHA
        sitekey="your-site-key"
        onChange={handleCaptchaChange}
      />
      <button type="submit">Submit</button>
    </form>
  );
}

export default MyForm;

Invisible reCAPTCHA

This code demonstrates how to use the invisible reCAPTCHA. The `ReCAPTCHA` component is set to `size="invisible"`, and the reCAPTCHA is executed programmatically when the form is submitted.

import React from 'react';
import ReCAPTCHA from 'react-google-recaptcha';

function MyForm() {
  const recaptchaRef = React.createRef();

  const handleSubmit = (event) => {
    event.preventDefault();
    recaptchaRef.current.execute();
  };

  const handleCaptchaChange = (value) => {
    console.log('Captcha value:', value);
    // Proceed with form submission
  };

  return (
    <form onSubmit={handleSubmit}>
      <ReCAPTCHA
        ref={recaptchaRef}
        sitekey="your-site-key"
        size="invisible"
        onChange={handleCaptchaChange}
      />
      <button type="submit">Submit</button>
    </form>
  );
}

export default MyForm;

reCAPTCHA v3

This code demonstrates how to use reCAPTCHA v3, which does not require user interaction. The `ReCAPTCHA` component is set to `size="invisible"` and an `action` is specified. The reCAPTCHA token is generated and can be verified on the server.

import React from 'react';
import ReCAPTCHA from 'react-google-recaptcha';

function MyForm() {
  const recaptchaRef = React.createRef();

  const handleSubmit = (event) => {
    event.preventDefault();
    recaptchaRef.current.execute();
  };

  const handleCaptchaChange = (token) => {
    console.log('Captcha token:', token);
    // Verify token with your server
  };

  return (
    <form onSubmit={handleSubmit}>
      <ReCAPTCHA
        ref={recaptchaRef}
        sitekey="your-site-key"
        size="invisible"
        onChange={handleCaptchaChange}
        action="submit"
      />
      <button type="submit">Submit</button>
    </form>
  );
}

export default MyForm;

Other packages similar to react-google-recaptcha

Keywords

FAQs

Package last updated on 03 Jun 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc