npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hash070/react-recaptcha-v2

v2.0.2

Published

Google reCAPTCHA v2 React component that does not pollute the DOM

Downloads

70

Readme

React reCAPTCHA v2

npm (scoped) license: mit code style: prettier

React wrapper component for Google's reCAPTCHA v2 service, built with TypeScript and Rollup, forked from matei-radu/react-recaptcha-v2.

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.
  • Use www.recaptcha.net to support global users.

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

| React | Library | Status | End-of-Life | | :---------------: | :---------------------------------------: | :-------------: | :---------: | | >=16.8.0 | npm (scoped) | Active | - | | 16.0.0 - 16.7.x | npm v1 (scoped) | Maintenance | 2023-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.

| Prop | Type | Default | Description | | ----------- | --------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | siteKey | string | undefined | Required. Your site key or the value "test" which will inject the test key. | | theme | light | dark | light | The color theme of the widget. | | size | normal | compact | normal | The size of the widget. | | onSuccess | function | undefined | Callback function, executed when the user submits a successful response. The response token is passed to your callback. | | onError | function | undefined | Callback 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. | | onExpire | function | undefined | Callback 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.