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

react-recaptcha-that-works

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-recaptcha-that-works

⚛ A reCAPTCHA bridge for React that works.

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2K
decreased by-15.96%
Maintainers
1
Weekly downloads
 
Created
Source

reCAPTCHA for React

License MIT npm version npm downloads

A reCAPTCHA library for React that works.

Looking for React Native version?

Install

Install the module

  yarn add react-recaptcha-that-works

Or

  npm i -S react-recaptcha-that-works

Import the reCAPTCHA script

<html>
    <head>
        <script src="https://www.google.com/recaptcha/api.js" async defer></script>
    </head>
    <body>
        ...
    </body>
</html>

Usage

I'm not a robot

import React, { Component } from 'react';

import Recaptcha from 'react-recaptcha-that-works';

class App extends Component {

    send = () => {
        console.log('send!', this.state.token);
    }

    onVerify = token => {
        console.log('success!', token);
        this.setState({ token });
    }

    onExpire = () => {
        console.warn('expired!');
    }

    render() {
        return (
            <div>
                <input type="text" placeholder="Username" />
                <input type="password" placeholder="Password" />
                <Recaptcha
                    siteKey="<your-recaptcha-public-key>"
                    onVerify={this.onVerify}
                    onExpire={this.onExpire}
                />
                <button onClick={this.send}>Send</button>
            </div>
        )
    }
}

Invisible

import React, { Component } from 'react';

import Recaptcha from 'react-recaptcha-that-works';

class App extends Component {

    send = () => {
        console.log('send!');
        this.recaptcha.execute();
    }

    onVerify = token => {
        console.log('success!', token);
    }

    onExpire = () => {
        console.warn('expired!');
    }

    render() {
        return (
            <div>
                <input type="text" placeholder="Username" />
                <input type="password" placeholder="Password" />
                <Recaptcha
                    ref={ref = this.recaptcha = ref}
                    siteKey="<your-recaptcha-public-key>"
                    onVerify={this.onVerify}
                    onExpire={this.onExpire}
                    size="invisible"
                />
                <button onClick={this.send}>Send</button>
            </div>
        )
    }
}

TypeScript

import React, { useRef } from 'react';

import Recaptcha, { RecaptchaRef } from "react-recaptcha-that-works";

// ...

export const Component: React.FC = () => {
    const recaptcha = useRef<RecaptchaRef>(null);

    const send = () => {
        console.log('send!');
        recaptcha.current?.execute();
    };

    const onVerify = (token: string) => {
        console.log('success!', token);
    };

    const onExpire = () => {
        console.warn('expired!');
    }

    return (
        <div>
            <Recaptcha
                ref={recaptcha}
                siteKey="<your-recaptcha-public-key>"
                onVerify={onVerify}
                onExpire={onExpire}
                size="invisible"
            />
            <button onClick={send}>
                Send
            </button>
        </div>
    );
};

For more details, see the Sample Project.

Props

NameValueDefaultDescription
siteKeyYour sitekey.
size'invisible', 'normal' or 'compact''normal'The size of the widget.
theme'dark' or 'light''light'The color theme of the widget.
onLoadfunction()A callback function, executed when the reCAPTCHA is ready to use.
onVerifyfunction(token)A callback function, executed when the user submits a successful response. The reCAPTCHA response token is passed to your callback.
onExpirefunction()A callback function, executed when the reCAPTCHA response expires and the user needs to re-verify.
onErrorfunction()A 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.
onClosefunction()(Experimental) A callback function, executed when the challenge window is closed.

React Ref Methods

NameTypeDescription
executefunctionExecutes the challenge in "invisible" mode.
resetfunctionResets the reCAPTCHA state.

reCAPTCHA v2 docs

Contribute

New features, bug fixes and improvements are welcome! For questions and suggestions, use the issues.

Become a Patron! Donate

License

The MIT License (MIT)

Copyright (c) 2018 Douglas Nassif Roma Junior

See the full license file.

Keywords

FAQs

Package last updated on 23 Oct 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