Skip to content

Commit fd01134

Browse files
committed
Only fetch recaptcha token once.
1 parent 8bbb542 commit fd01134

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

frontend/packages/volto-form-block/src/components/Widgets/GoogleReCaptchaWidget.jsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useCallback, useRef } from 'react';
1+
import React, { useState } from 'react';
22
import { injectLazyLibs } from '@plone/volto/helpers/Loadable/Loadable';
33
import { useIntl } from 'react-intl';
44

@@ -7,14 +7,22 @@ const GoogleReCaptchaWidget = (props) => {
77

88
const { GoogleReCaptchaProvider, GoogleReCaptcha } = recaptchalib;
99
const intl = useIntl();
10+
const [submitted, setSubmitted] = useState(false);
1011

1112
return (
12-
<GoogleReCaptchaProvider
13-
reCaptchaKey={captcha_props.public_key}
14-
language={intl.locale ?? 'en'}
15-
>
16-
<GoogleReCaptcha onVerify={(token) => onChange(id, token)} />
17-
</GoogleReCaptchaProvider>
13+
!submitted && (
14+
<GoogleReCaptchaProvider
15+
reCaptchaKey={captcha_props.public_key}
16+
language={intl.locale ?? 'en'}
17+
>
18+
<GoogleReCaptcha
19+
onVerify={(token) => {
20+
setSubmitted(true);
21+
onChange(id, token);
22+
}}
23+
/>
24+
</GoogleReCaptchaProvider>
25+
)
1826
);
1927
};
2028

0 commit comments

Comments
 (0)