The HCaptcha component is the primary entry point for integrating hCaptcha into a React application. It handles script loading, widget rendering, and provides a bridge to the underlying hCaptcha API. You can pass various configuration props to customize the widget's appearance, behavior, and callbacks.
import { HCaptcha } from '@hcaptcha/react-hcaptcha';
function MyForm() {
const handleVerify = (token, ekey) => {
console.log('Verification token:', token);
console.log('Response key:', ekey);
};
return (
<HCaptcha
sitekey="YOUR_SITE_KEY"
onVerify={handleVerify}
onExpire={() => console.log('Captcha expired')}
onError={(err) => console.error('Captcha error:', err)}
/>
);
}