1.3.1 • Published 4 months ago

@captchafox/react v1.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@captchafox/react

NPM version

Installation

Install the library using your prefered package manager

npm install @captchafox/react
yarn add @captchafox/react
pnpm add @captchafox/react
bun add @captchafox/react

Usage

import { CaptchaFox } from '@captchafox/react';

function Example() {
  return <CaptchaFox sitekey="sk_11111111000000001111111100000000" />;
}

Props

PropTypeDescriptionRequired
sitekeystringThe sitekey for the widget
langstringThe language the widget should display. Defaults to automatically detecting it.
modeinline\|popup\|hiddenThe mode the widget should be displayed in .
themelight | dark | ThemeDefinitionThe theme of the widget. Defaults to light.
onVerifyfunctionCalled with the response token after successful verification.
onFailfunctionCalled after unsuccessful verification.
onErrorfunctionCalled when an error occured.
onExpirefunctionCalled when the challenge expires.
onClosefunctionCalled when the challenge was closed.

Using the verification callback

import { CaptchaFox, CAPTCHA_RESPONSE_KEY } from '@captchafox/react';

function Example() {
  const handleVerify = (token: string) => {
    // do something with the token here (e.g. submit the form)
    const formData = {
      // your form data
      [CAPTCHA_RESPONSE_KEY]: token
    };
  };

  return <CaptchaFox sitekey="sk_11111111000000001111111100000000" onVerify={handleVerify} />;
}

Interacting with the instance

import { useRef } from 'react'
import { CaptchaFox, CaptchaFoxInstance } from '@captchafox/react'

function Example() {
    const captchaRef = useRef<CaptchaFoxInstance | null>(null);

    const triggerAction = async () => {
        // execute the captcha
        try {
            const token = await captchaRef.current?.execute()
        } catch {
            // unsuccessful verification
        }
    }

    return (
        <CaptchaFox
            sitekey="sk_11111111000000001111111100000000"
            ref={captchaRef}
        />
        <button onClick={triggerAction}>Action</button>
    )
}

You can find more detailed examples in the GitHub repository.

1.3.1

4 months ago

1.3.0

4 months ago

1.2.0

7 months ago

1.1.1

9 months ago

1.1.0

11 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago