React Invisible Recaptcha
A simple React component to create Google invisible recaptchas
Install
npm install react-invisible-recaptcha --save
Or use Yarn:
yarn add react-invisible-recaptcha
Example
Below is a component which implements the recaptcha.
Component { super props ; thisstate = value: '' ; thisonSubmit = thisonSubmit; thisonResolved = thisonResolved; } { return <div> <input type="text" value= thisstatevalue onChange= this /> <button onClick= thisonSubmit >Submit</button> <Recaptcha ref= thisrecaptcha = ref sitekey="<sitekey>" onResolved= thisonResolved /> </div> ; } { if '' == thisstatevalue ; thisrecaptcha; else thisrecaptcha; } { ; }
Usage
; <Recaptcha ref= thisrecaptcha = ref sitekey= <sitekey> onResolved= console />
Configuration
Set required props to get going.
- sitekey: sitekey for your recaptcha. Required.
A few optional props you can tweak.
- badge:
bottomright
,bottomleft
, orinline
. Default: bottomright. - locale: in which language it speaks. Default: en.
- nonce: nonce included in the reCAPTCHA script tag. Default: undefined.
- onResolved: callback when the recaptcha is resolved. Default: noop.
- onError: callback when the recaptcha encounters an error. Default: noop.
- onExpired: callback when the recaptcha response expires. Default: noop.
- onLoaded: callback when the recaptcha is loaded. Default: noop.
- style: custom CSS applied to the root node. Default: undefined.
- tabindex: tabindex of the challenge. Default: 0.
- trustedTypesPolicy: the Trusted Types policy to use for the script url. Default: null.
APIs
<Recaptcha ref= thisrecaptcha = ref ... />
- this.recaptcha.execute function which invokes the reCAPTCHA check.
- this.recaptcha.reset function which resets the reCAPTCHA widget.
- this.recaptcha.getResponse function which returns the response token.
License
MIT. See LICENSE.md for details.