Socket
Socket
Sign inDemoInstall

@matt-block/react-recaptcha-v2

Package Overview
Dependencies
4
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

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


Version published
Weekly downloads
729
increased by5.81%
Maintainers
1
Install size
37.4 kB
Created
Weekly downloads
 

Changelog

Source

[2.0.1] - 2022-05-03

Changed

  • Updating TypeScript to v4.9 has fixed Rollup not being able to output type declarations, so the npm script build:ts-decl is removed.
  • TypeScript declarations are now available under lib instead of types.
  • Move lint-staged configuration to its own file .lintstagedrc.json.
  • Bump @rollup/plugin-node-resolve to version 15.0.2.
  • Bump @rollup/plugin-typescript to version 11.1.0.
  • Bump @types/react to version 18.2.1.
  • Bump husky to version 8.0.3.
  • Bump lint-staged to version 13.2.2.
  • Bump prettier to version 2.8.8.
  • Bump rollup to version 3.21.4.
  • Bump typescript to version 4.9.5.

Removed

  • tslib dev-dependency because it was unnecessary. The built code includes only one implementation of __rest so there is no duplication that tslib was solving.

Readme

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 type declarations

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):

ReactLibraryStatusEnd-of-Life
>=16.8.0npm (scoped)Active-
16.0.0 - 16.7.xnpm v1 (scoped)Maintenance2023-06-01

Migrating from 1.x to 2.x

The current version requires React 16.8.0 or above. If you are stuck with an older version, you could:

  • Not migrate to version 2 and continue to use a 1.x release, though support will end soon.
  • Move to a different package for Google reCAPTCHA v2, like:

Installation

Install the package via npm or Yarn:

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

// or

yarn add @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 from "react";
import ReCaptcha from "@matt-block/react-recaptcha-v2";

const MyFormComponent = () => {
  // other logic and hooks...

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

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.
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.
onExpirefunctionundefinedCallback function, executed when the reCAPTCHA response expires and the user needs to re-verify.

Contributing

If you are looking to contribute to this project, check CONTRIBUTING.md.

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

Last updated on 03 May 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc