Skip to content

Commit

Permalink
chore: Better onload
Browse files Browse the repository at this point in the history
  • Loading branch information
kevee committed Sep 11, 2020
1 parent b194bbb commit c4bfa3f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/components/common/recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@ const Recaptcha = () => {
const captchaRef = useRef(false)

useEffect(() => {
if (
typeof window !== 'undefined' &&
typeof window.grecaptcha !== 'undefined'
) {
window.grecaptcha.render(captchaRef.current, {
siteKey: data.site.siteMetadata.recaptchaKey,
})
}
if (typeof window !== 'undefined')
window.recaptchaOnload = () => {
window.grecaptcha.render(captchaRef.current, {
siteKey: data.site.siteMetadata.recaptchaKey,
})
}
}, [])

return (
<>
<Helmet>
<script src="https://www.google.com/recaptcha/api.js?render=explicit" />
<script src="https://www.google.com/recaptcha/api.js?render=explicit&onload=recaptchaOnload" />
</Helmet>
<div
className="g-recaptcha"
ref={captchaRef}
data-sitekey={data.site.siteMetadata.recaptchaKey}
/>
</>
Expand Down

0 comments on commit c4bfa3f

Please sign in to comment.