1.0.2 • Published 2 years ago

react-cf-turnstile v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Cloudflare Turnstile React Library

This library provides a React component that can be used to protect your site from bots and scrapers using Cloudflare Turnstile.

Basic usage can be found at the Cloudflare Turnstile Documentation.

Installation

npm i react-cf-turnstile
yarn add react-cf-turnstile

Methods

Methods can be called using a reference. Passing the widget ID is not necessary.

NameDescription
renderTurnstileCalls the turnstile.render() function
resetTurnstileCan be used to reset the widget if it has expired or needs to be reloaded
removeTurnstileRemoves the widget
getResponsesoon™

Props

NameTypeRequiredDescription
sitekeystringyesThe sitekey associated with your widget configuration on the Cloudflare Dashboard
actionstringInformation used in analytics to differentiate between widgets on the same site
cDatastringPayload used to attach customer data to the challenge which is returned upon validation
callbackcallbackyesCalled when a challenge is successfully completed
expired-callbackcallbackCalled when a challenge expires
error-callbackcallbackCalled when there is a network error
themestringTheme of the widget. Can be light, dark or auto
tabindexnumberTabindex of the iframe for accessibility purposes

Example

In this example, I use the demo only sitekey provided by Cloudflare. You should use your own sitekey in production.

import React from 'react';
import CFTurnstile from 'react-cf-turnstile';

function App() {
  return (
    <CFTurnstile
      siteKey="1x00000000000000000000AA" // change me! testing only
      action="FORM_SUBMIT" // optional: used in analytics to differentiate between different turnstiles on the same site
      cData="some data" // optional: read cloudflare docs for more info
      callback={(token) => { // called when challenge is completed successfully
        console.log(token);
      }}
      expired-callback={() => { // optional: called when a challenge expires
        console.log('expired');
      }}
      error-callback={(error) => { // optional: called when an error occurs
          console.error(error);
      }}
      theme="light" // optional: light/dark/auto
      tabindex="0" // optional: tabindex for the iframe for accessibility
    />
  );
}

Feeling experimental? Grab the latest dev build

Note: dev builds are not guaranteed to be stable and may contain breaking changes not clearly documented

npm i react-cf-turnstile@dev
yarn add react-cf-turnstile@dev
1.0.2

2 years ago

1.0.2-dev.1

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.0-dev.2

2 years ago

0.1.0

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago