Skip to content

Commit aadc41e

Browse files
committed
don't remount on change to allowAnonymousTelemetry
1 parent 5172dd7 commit aadc41e

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed
+3-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import posthog from "posthog-js";
22
import { PostHogProvider } from "posthog-js/react";
3-
import React, { PropsWithChildren, useEffect } from "react";
3+
import { PropsWithChildren, useEffect } from "react";
44
import { useAppSelector } from "../redux/hooks";
55

66
const CustomPostHogProvider = ({ children }: PropsWithChildren) => {
77
const allowAnonymousTelemetry = useAppSelector(
88
(store) => store?.config?.config?.allowAnonymousTelemetry,
99
);
1010

11-
const [client, setClient] = React.useState<any>(undefined);
12-
1311
useEffect(() => {
1412
if (allowAnonymousTelemetry) {
1513
posthog.init("phc_JS6XFROuNbhJtVCEdTSYk6gl5ArRrTNMpCcguAXlSPs", {
@@ -22,17 +20,12 @@ const CustomPostHogProvider = ({ children }: PropsWithChildren) => {
2220
});
2321
posthog.identify(window.vscMachineId);
2422
posthog.opt_in_capturing();
25-
setClient(client);
2623
} else {
27-
setClient(undefined);
24+
posthog.opt_out_capturing();
2825
}
2926
}, [allowAnonymousTelemetry]);
3027

31-
return allowAnonymousTelemetry ? (
32-
<PostHogProvider client={client}>{children}</PostHogProvider>
33-
) : (
34-
<>{children}</>
35-
);
28+
return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
3629
};
3730

3831
export default CustomPostHogProvider;

0 commit comments

Comments
 (0)