@ captchafox/ 反应
安装
使用您喜欢的软件包管理器安装库
npm install @captchafox/react
yarn add @captchafox/react
pnpm add @captchafox/react
bun add @captchafox/react
使用量
import { CaptchaFox } from '@captchafox/react';
function Example() {
return <CaptchaFox sitekey="sk_11111111000000001111111100000000" />;
}
道具
| Prop | 类型 | 说明 | 需求 |
|---|---|---|---|
| 站台密钥 | string | 部件的站点密钥 | ✅ |
| 朗语 | string | 部件应显示的语言 。 默认自动检测它. | |
| 模式 | inline|popup|hidden | 部件应显示在 . | |
| 开始 | none|auto|focus | 核查开始时的控制。 默认为 none。 。 。 . | |
| 主题 | light | dark | ThemeDefinition | 部件的主题 。 默认为光. | |
| 无 | string | 随机生成的非ce. | |
| i18n (英语) | object | 自定义i18n配置. | |
| 隐藏 | boolean | 隐藏关闭按钮并阻止用户关闭部件模式. | |
| 认证 | function | 在成功核实后,以响应符号调用. | |
| 失败 | function | 在核查失败后打电话. | |
| 错误 | function | 当错误发生时调用 . | |
| 结束 | function | 当挑战结束时召唤. | |
| 关闭 | function | 当挑战结束时打电话来. |
使用验证回调
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} />;
}
与实例互动
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>
)
}
您可以在 GitHub 仓库。 。 。 .