Skip to content

Instantly share code, notes, and snippets.

@kiuKisas
Created February 12, 2021 16:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiuKisas/e022a4a827207cc7cc28739c16b7627b to your computer and use it in GitHub Desktop.
Save kiuKisas/e022a4a827207cc7cc28739c16b7627b to your computer and use it in GitHub Desktop.
Svelte Recaptcha
// Due to the nature of svelte, implementing recaptcha inside a svelte component by following the official documentation
// can lead to DOM issue.
// The best way I find is to render the recaptcha inside onMount
<script>
import { onMount } from 'svelte';
onMount(async () => {
window.grecaptcha.ready(() => {
grecaptcha.render('recaptcha-id', { sitekey: YOUR_SITE_KEY })
})
})
</script>
<svelte:head>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</svelte:head>
<div id="recaptcha-id"></div>
@basaran
Copy link

basaran commented Oct 21, 2021

I published a component that address most of these DOM issues.

https://github.com/basaran/svelte-recaptcha-v2

This is also on npm as svelte-recaptcha-v2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment