Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@matt-block/react-recaptcha-v2

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@matt-block/react-recaptcha-v2

Google reCAPTCHA v2 React component that does not pollute the DOM

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2K
increased by81.75%
Maintainers
1
Weekly downloads
 
Created
Source

React reCAPTCHA v2

npm (scoped) license: mit code style: prettier

React wrapper component for Google's reCAPTCHA v2 service, built with Typescript and Rollup.

Features

  • Does not pollute the DOM by cleaning up on unmount (see below)
  • Can safely add multiple <ReCaptcha> components in the same page, they will not conflict with each other.
  • Typescript and Flow definitions
  • Actively developed

DOM Pollution and Cleanup

<ReCaptcha> will handle all its dirt that is automatically added to the DOM: according to the official reCAPTCHA Documentation, a <script> must be added in the head section of our HTML document. However, it is not explained that, once that script is loaded, more elements will be automatically added to the DOM, outside of out React tree.

Once the component is unmounted, all that has been directly and indirectly added will be removed, leaving a clean document:

Cleanup

Compatibility

This library will always target the most recent React package. If you are using an older release of React, use the correct version of this library from the compatibility table below (if available):

ReactLibrary
>=16.0.0latest

Installation

Install the package via Yarn or npm:

yarn add @matt-block/react-recaptcha-v2

// or

npm install --save @matt-block/react-recaptcha-v2

That is all, no <script> needs to be added to your main HTML file as this is handled automatically by the component.

Usage

import React, { Component } from "react";
import ReCaptcha from "@matt-block/react-recaptcha-v2";

class MyFormComponent extends Component {
  // other methods and callbacks...

  render() {
    return (
      {/* other components to render... */}
      <ReCaptcha
        siteKey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
        theme="light"
        size="normal"
        onSuccess={(captcha) => console.log(`Successful, result is ${captcha}`)}
        onExpire={() => console.log("Verification has expired, re-verify.")}
        onError={() => console.log("Something went wrong, check your conenction")}
      />
    );
  }
}

Props

The only mandatory prop is siteKey which can be obtained from the reCAPTCHA Admin Panel, all other props are optional.

PropTypeDefaultDescription
siteKeystringundefinedRequired. Your site key or the value "test" which will inject the test key.
themelight | darklightThe color theme of the widget.
sizenormal | compactnormalThe size of the widget.
onSuccessfunctionundefinedCallback function, executed when the user submits a successful response. The response token is passed to your callback.
onExpiredfunctionundefinedCallback function, executed when the reCAPTCHA response expires and the user needs to re-verify.
onErrorfunctionundefinedCallback function, executed when reCAPTCHA encounters an error (usually network connectivity) and cannot continue until connectivity is restored. If you specify a function here, you are responsible for informing the user that they should retry.

License

Copyright (c) 2018-present Matei Bogdan Radu.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.

Keywords

FAQs

Package last updated on 09 Jun 2019

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