Skip to content

Commit 76aabd6

Browse files
committed
fix(project): fix lots of things
1 parent 3b17844 commit 76aabd6

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function useHotjar(): TUseHotjar {
3535
const identityHotjar = React.useCallback(
3636
(userId: string, userInfo: string, shouldLog = true): boolean => {
3737
try {
38-
const hotjarIdentityScript = `var userId="${userId}" || null;window.hj("identify",userId,{${userInfo}}});`;
38+
const hotjarIdentityScript = `var userId="${userId}" || null;window.hj("identify",userId,${userInfo});`;
3939
const isIdentified = appendHeadScript({
4040
scriptText: hotjarIdentityScript,
4141
scriptId: 'identity-script',

src/useAppendHeadScript.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ type TUseAppendHeadScript = {
1010
};
1111

1212
export function useAppendHeadScript(): TUseAppendHeadScript {
13-
const appendHeadScript = ({
14-
scriptText,
15-
scriptId,
16-
}: TAppendHeadScript): boolean => {
17-
try {
18-
const existentScript = document.getElementById(
19-
scriptId
20-
) as HTMLScriptElement;
21-
const script = existentScript || document.createElement('script');
22-
script.id = scriptId;
23-
script.innerText = scriptText;
24-
script.crossOrigin = 'anonymous';
13+
const appendHeadScript = React.useCallback(
14+
({ scriptText, scriptId }: TAppendHeadScript): boolean => {
15+
try {
16+
const existentScript = document.getElementById(
17+
scriptId
18+
) as HTMLScriptElement;
19+
const script = existentScript || document.createElement('script');
20+
script.id = scriptId;
21+
script.innerText = scriptText;
22+
script.crossOrigin = 'anonymous';
2523

26-
document.head.appendChild(script);
24+
document.head.appendChild(script);
2725

28-
return true;
29-
} catch (error) {
30-
return error;
31-
}
32-
};
26+
return true;
27+
} catch {
28+
return false;
29+
}
30+
},
31+
[]
32+
);
3333

34-
return React.useMemo(() => ({ appendHeadScript }), []);
34+
return React.useMemo(() => ({ appendHeadScript }), [appendHeadScript]);
3535
}

0 commit comments

Comments
 (0)