1.1.0 • Published 4 months ago

@captchafox/solid v1.1.0

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

@captchafox/solid

NPM version

Installation

Install the library using your prefered package manager

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

Usage

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

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/solid';

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 { CaptchaFox, CaptchaFoxInstance } from '@captchafox/solid'

function Example() {
    let captchaRef: CaptchaFoxInstance;

    const triggerAction = async () => {
        // execute the captcha
        try {
            const token = await captchaRef.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.1.0

4 months ago

1.0.0

5 months ago