appleboy / react-recaptcha

A react.js reCAPTCHA for Google
https://www.google.com/recaptcha/intro/index.html
BSD 3-Clause "New" or "Revised" License
635 stars 97 forks source link

reCAPTCHA has already been rendered in this element #262

Open philonor opened 4 years ago

philonor commented 4 years ago

Description When using react-recaptcha in a GatsbyJS project and switching between pages containing the same component with a reCAPTCHA, rendering fails. It also fails when opening a direct link to one of the two pages.

gatsby-recaptcha-reproduction

Reproduction

Workarounds

Related

fresquer commented 4 years ago

@philonor as I found here https://github.com/appleboy/react-recaptcha/issues/229 the issue is really easy to fix.

Use isBrowser of useSSR Hook https://github.com/alex-cory/use-ssr

{isBrowser && <Recaptcha/> }

rlaphoenix commented 4 years ago

@fernandopulsa Saved my ass!, But is there a reason we don't just do { typeof window !== 'undefined' && <Recaptcha /> } as window will be undefined when in SSR.

fresquer commented 4 years ago

Gatsby JS is not a SSR tool. If you try to use windows on the server will crush. To protect you for any undefined you must to use window with componentDidMount()

More info: https://github.com/gatsbyjs/gatsby/issues/309

senorgeno commented 4 years ago

Using a unique elementID worked for me.