--- title: React-SDK --- # React-SDK Offizielle React-Komponente und Hook für CaptchaLa CAPTCHA — veröffentlicht als [`@captcha-la/react`](https://www.npmjs.com/package/@captcha-la/react). ## Live-Demo ::: tip 📦 [demo-v1.captcha.la/react](https://demo-v1.captcha.la/react/) — lauffähige Demo mit allen vier Produkt-Modi. Quellcode: [Captcha-La/react-example](https://github.com/Captcha-La/react-example). ::: ## Installation ```bash npm install @captcha-la/react # or yarn add @captcha-la/react # or pnpm add @captcha-la/react ``` Peer-Abhängigkeiten: `react@^17 || ^18 || ^19`, `react-dom@^17 || ^18 || ^19`. ## Schnellstart ### Komponente ```tsx import { Captchala } from '@captcha-la/react' function App() { return ( console.log('pass_token:', result.token)} onError={(err) => console.error(err)} /> ) } ``` ### Hook ```tsx import { useCaptchala } from '@captcha-la/react' function LoginForm() { const { ready, verify } = useCaptchala({ appKey: 'your-app-key', product: 'bind', action: 'login', }) async function handleSubmit(e) { e.preventDefault() const result = await verify() // result.token → submit with the form } return (
) } ``` ## Props | Prop | Typ | Standard | Beschreibung | |------|------|---------|-------------| | `appKey` | `string` | *erforderlich* | CaptchaLa Application Key | | `serverToken` | `string` | - | Einmal-Challenge-Token, der vom Server ausgestellt wird. Erforderlich, wenn für die Anwendung `server_token_required=true` gesetzt ist. | | `product` | `'popup' \| 'float' \| 'embed' \| 'bind'` | `'popup'` | Anzeigemodus | | `action` | `string` | `'default'` | Action-Bezeichner | | `lang` | `string` | `'zh-CN'` | Sprachcode | | `onSuccess` | `(result) => void` | - | Erfolgs-Callback | | `onError` | `(error) => void` | - | Fehler-Callback | | `onClose` | `() => void` | - | Close-Callback | | `onReady` | `() => void` | - | Ready-Callback | | `className` | `string` | - | Container-Klassenname | | `style` | `CSSProperties` | - | Inline-Styles für den Container | ## Methoden (via `ref`) ```tsx import { useRef } from 'react' import { Captchala, type CaptchalaRef } from '@captcha-la/react' function App() { const ref = useRef(null) return ( <> ) } ``` | Methode | Beschreibung | |--------|-------------| | `verify()` | Verifizierung auslösen | | `reset()` | CAPTCHA-Status zurücksetzen | | `destroy()` | Instanz zerstören | | `bindTo(selector)` | An Element binden (für `bind`-Modus) | | `setLang(lang)` | Sprache zur Laufzeit wechseln | ## Produktion: `serverToken`-Modus ```tsx import { useState, useEffect } from 'react' import { Captchala } from '@captcha-la/react' function LoginPage() { const [token, setToken] = useState() useEffect(() => { fetch('/api/captcha-token') // your own backend .then((r) => r.json()) .then((d) => setToken(d.server_token)) }, []) if (!token) return
Loading…
return ( console.log('pass_token:', r.token)} /> ) } ``` Siehe [API-Referenz](/de/api-reference) für den vollständigen Backend-Vertrag. ## Links - [npm](https://www.npmjs.com/package/@captcha-la/react) · [GitHub](https://github.com/Captcha-La/react) · [Beispiel](https://github.com/Captcha-La/react-example) - [Web-SDK-Übersicht](/de/web-sdk) · [API-Referenz](/de/api-reference)