Skip to content

Commit f89b99f

Browse files
committed
some lint fixes
1 parent df84dea commit f89b99f

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

src/google-recaptcha-provider.tsx

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,34 @@ enum GoogleRecaptchaError {
1717
SCRIPT_NOT_AVAILABLE = 'Recaptcha script is not available'
1818
}
1919

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+
2040
interface IGoogleReCaptchaProviderProps {
2141
reCaptchaKey: string;
2242
language?: string;
2343
useRecaptchaNet?: boolean;
2444
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;
3346
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;
4448
children: ReactNode;
4549
}
4650

@@ -74,8 +78,9 @@ export function GoogleReCaptchaProvider({
7478
execute: Function;
7579
}>(null);
7680
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);
7984

8085
useEffect(() => {
8186
if (!reCaptchaKey) {
@@ -86,8 +91,8 @@ export function GoogleReCaptchaProvider({
8691
return;
8792
}
8893

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';
9196

9297
((window as unknown) as {[key: string]: () => void})[onLoadCallbackName] = () => {
9398
/* eslint-disable @typescript-eslint/no-explicit-any */
@@ -99,7 +104,7 @@ export function GoogleReCaptchaProvider({
99104
badge: 'inline',
100105
size: 'invisible',
101106
sitekey: reCaptchaKey,
102-
...(parametersRef || {})
107+
...(parameters || {})
103108
};
104109
clientId.current = grecaptcha.render(inlineBadgeId, params);
105110
};
@@ -131,7 +136,7 @@ export function GoogleReCaptchaProvider({
131136
onLoadCallbackName,
132137
useEnterprise,
133138
useRecaptchaNet,
134-
scriptProps: scriptPropsRef,
139+
scriptProps,
135140
language,
136141
onLoad,
137142
onError
@@ -143,8 +148,8 @@ export function GoogleReCaptchaProvider({
143148
}, [
144149
useEnterprise,
145150
useRecaptchaNet,
146-
scriptPropsRef,
147-
parametersRef,
151+
scriptPropsJson,
152+
parametersJson,
148153
language,
149154
reCaptchaKey
150155
]);

src/google-recaptcha.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { logWarningMessage } from './utils';
55
export interface IGoogleRecaptchaProps {
66
onVerify: (token: string) => void | Promise<void>;
77
action?: string;
8-
refreshReCaptcha?: any,
8+
refreshReCaptcha?: boolean | string | number | null;
99
}
1010

1111
export function GoogleReCaptcha({
@@ -19,8 +19,7 @@ export function GoogleReCaptcha({
1919
const { executeRecaptcha } = googleRecaptchaContextValue;
2020

2121
if (!executeRecaptcha) {
22-
// return value is not used, but here is used to avoid unused dependencies
23-
return refreshReCaptcha;
22+
return;
2423
}
2524

2625
const handleExecuteRecaptcha = async () => {

0 commit comments

Comments
 (0)