Skip to content

Commit f01e949

Browse files
committed
Lazy load recaptcha only if configured
1 parent 2ac0367 commit f01e949

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/components/App.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import React from 'react'
1+
import React, { lazy, Suspense } from 'react'
22

33
import { BrowserRouter, Redirect, Route, Switch } from 'react-router-dom'
44

55
import Election from './Election'
66

7-
import { GoogleReCaptchaProvider } from 'react-google-recaptcha-v3'
87
import styled from 'styled-components'
98
import Embed from './Embed'
109
import './recaptcha/recaptcha.css'
@@ -45,6 +44,12 @@ const GlobalCSS = styled.div`
4544
}
4645
`
4746

47+
const GoogleReCaptchaProvider = lazy(() =>
48+
import('react-google-recaptcha-v3').then((module) => ({
49+
default: module.GoogleReCaptchaProvider,
50+
}))
51+
)
52+
4853
export default (props) => {
4954
const publicURL = process.env.PUBLIC_URL ? process.env.PUBLIC_URL : '/'
5055
const reCaptchaKey = process.env.GOOGLE_RECAPTCHA_KEY
@@ -62,9 +67,11 @@ export default (props) => {
6267
)
6368

6469
return reCaptchaKey ? (
65-
<GoogleReCaptchaProvider reCaptchaKey={reCaptchaKey} language="bg">
66-
{app}
67-
</GoogleReCaptchaProvider>
70+
<Suspense fallback={app}>
71+
<GoogleReCaptchaProvider reCaptchaKey={reCaptchaKey} language="bg">
72+
{app}
73+
</GoogleReCaptchaProvider>
74+
</Suspense>
6875
) : (
6976
app
7077
)

0 commit comments

Comments
 (0)