diff --git a/src/pages/index.js b/src/pages/index.js index f6fc1b2..f0d1f29 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -4,38 +4,40 @@ import { content_pl } from "../content/kamil" import { content_en } from "../content/kamil" import ReCAPTCHA from "react-google-recaptcha" -const RECAPTCHA_SITE_KEY = process.env.GATSBY_RECAPTCHA_SITE_KEY || "YOUR_RECAPTCHA_SITE_KEY" +// Klucz strony reCAPTCHA +const RECAPTCHA_SITE_KEY = process.env.GATSBY_RECAPTCHA_SITE_KEY || "YOUR_RECAPTCHA_SITE_KEY"; +// Komponent obsługujący reCAPTCHA const CaptchaWrapper = ({ onVerified }) => { const [error, setError] = React.useState(null); - const isMounted = React.useRef(true); + const recaptchaRef = React.useRef(null); - React.useEffect(() => { - return () => { - isMounted.current = false; - }; - }, []); - - const handleCaptchaChange = (value) => { - if (isMounted.current && value) { - onVerified(true); - setError(null); - } - }; - - const handleCaptchaError = () => { - if (isMounted.current) { - setError('Wystąpił błąd podczas weryfikacji CAPTCHA'); - onVerified(false); + const handleCaptchaChange = () => { + try { + const token = recaptchaRef.current.getValue(); + if (token) { + onVerified(true); + setError(null); + } + } catch (err) { + console.error("reCAPTCHA error:", err); + setError("Wystąpił błąd podczas weryfikacji. Spróbuj ponownie."); } }; return (