@@ -17,30 +17,34 @@ enum GoogleRecaptchaError {
17
17
SCRIPT_NOT_AVAILABLE = 'Recaptcha script is not available'
18
18
}
19
19
20
+ interface IScriptProps {
21
+ nonce ?: string ;
22
+ defer ?: boolean ;
23
+ async ?: boolean ;
24
+ appendTo ?: 'head' | 'body' ;
25
+ id ?: string ;
26
+ onLoadCallbackName ?: string ;
27
+ }
28
+
29
+ interface IParameters {
30
+ sitekey ?: string ;
31
+ badge ?: string ;
32
+ theme ?: string ;
33
+ size ?: string ;
34
+ tabindex ?: number ;
35
+ callback ?: ( ) => void ;
36
+ expiredCallback ?: ( ) => void ;
37
+ errorCallback ?: ( ) => void ;
38
+ }
39
+
20
40
interface IGoogleReCaptchaProviderProps {
21
41
reCaptchaKey : string ;
22
42
language ?: string ;
23
43
useRecaptchaNet ?: boolean ;
24
44
useEnterprise ?: boolean ;
25
- scriptProps ?: {
26
- nonce ?: string ;
27
- defer ?: boolean ;
28
- async ?: boolean ;
29
- appendTo ?: 'head' | 'body' ;
30
- id ?: string ;
31
- onLoadCallbackName ?: string ;
32
- } ;
45
+ scriptProps ?: IScriptProps ;
33
46
inlineBadgeId ?: string | HTMLElement ;
34
- parameters ?: {
35
- sitekey ?: string ;
36
- badge ?: string ;
37
- theme ?: string ;
38
- size ?: string ;
39
- tabindex ?: number ;
40
- callback ?: ( ) => void ;
41
- expiredCallback ?: ( ) => void ;
42
- errorCallback ?: ( ) => void ;
43
- } ;
47
+ parameters ?: IParameters ;
44
48
children : ReactNode ;
45
49
}
46
50
@@ -74,8 +78,9 @@ export function GoogleReCaptchaProvider({
74
78
execute : Function ;
75
79
} > ( null ) ;
76
80
const clientId = useRef < number | string > ( reCaptchaKey ) ;
77
- const { current : scriptPropsRef } = useRef < any > ( scriptProps ) ;
78
- const { current : parametersRef } = useRef < any > ( parameters ) ;
81
+
82
+ const scriptPropsJson = JSON . stringify ( scriptProps ) ;
83
+ const parametersJson = JSON . stringify ( parameters ) ;
79
84
80
85
useEffect ( ( ) => {
81
86
if ( ! reCaptchaKey ) {
@@ -86,8 +91,8 @@ export function GoogleReCaptchaProvider({
86
91
return ;
87
92
}
88
93
89
- const scriptId = scriptPropsRef ?. id || 'google-recaptcha-v3' ;
90
- const onLoadCallbackName = scriptPropsRef ?. onLoadCallbackName || 'onRecaptchaLoadCallback' ;
94
+ const scriptId = scriptProps ?. id || 'google-recaptcha-v3' ;
95
+ const onLoadCallbackName = scriptProps ?. onLoadCallbackName || 'onRecaptchaLoadCallback' ;
91
96
92
97
( ( window as unknown ) as { [ key : string ] : ( ) => void } ) [ onLoadCallbackName ] = ( ) => {
93
98
/* eslint-disable @typescript-eslint/no-explicit-any */
@@ -99,7 +104,7 @@ export function GoogleReCaptchaProvider({
99
104
badge : 'inline' ,
100
105
size : 'invisible' ,
101
106
sitekey : reCaptchaKey ,
102
- ...( parametersRef || { } )
107
+ ...( parameters || { } )
103
108
} ;
104
109
clientId . current = grecaptcha . render ( inlineBadgeId , params ) ;
105
110
} ;
@@ -131,7 +136,7 @@ export function GoogleReCaptchaProvider({
131
136
onLoadCallbackName,
132
137
useEnterprise,
133
138
useRecaptchaNet,
134
- scriptProps : scriptPropsRef ,
139
+ scriptProps,
135
140
language,
136
141
onLoad,
137
142
onError
@@ -143,8 +148,8 @@ export function GoogleReCaptchaProvider({
143
148
} , [
144
149
useEnterprise ,
145
150
useRecaptchaNet ,
146
- scriptPropsRef ,
147
- parametersRef ,
151
+ scriptPropsJson ,
152
+ parametersJson ,
148
153
language ,
149
154
reCaptchaKey
150
155
] ) ;
0 commit comments