I'm trying to add recaptcha v2 to my Gatsby/Netlify site form and i'm missing the last part that is actually displaying the widget. It just doesn't show up where it is placed.
So far my code is this
The gatsby-ssr.js file:
import React from "react"
export const onRenderBody = ({ setHeadComponents, setPostBodyComponents }) => {
setHeadComponents([
<script
dangerouslySetInnerHTML={{
__html: `
function onloadCallback() {
grecaptcha.render(document.getElementById('g-recaptcha'), {
"sitekey": '6LfMWLkaAAAAAFYM11ctU1Dxfz_v3SVrAKLOR3rM',
})
}
`,
}}
/>,
])
setPostBodyComponents([
<script
key="abc"
type="text/javascript"
src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
async
defer1
/>,
])
}
And the contact form:
<Form className="contact-form" method="post" data-netlify-recaptcha="true" data-netlify="true" netlify-honeypot="bot-field">
...
<p className="hidden">
<label>Don’t fill this out if you’re human: <input name="bot-field" /></label>
</p>
...
<Form.Group id="recaptcha-container">
<div id="g-recaptcha" className="g-recaptcha" data-netlify-recaptcha="true" render="explicit"></div>
</Form.Group>
...
</Form>
The error "Uncaught (in promise) Error: reCAPTCHA placeholder element must be an element or id" appeared before I added any Netlify attributes to my form, so I'm pretty sure that has nothing to do with it.
Any ideas? Thanks.