Fix: mounting state use theme (#7203)

Co-authored-by: Guest <[email protected]>
This commit is contained in:
Harsh SinghandGuest authored and GitHub committed 2023-02-20 15:17:33 +05:30
1 parent 4d2cf28c7e
commit 0e7276370f
3 files changed
+10 -30

No files matched your search

-22
View File
@@ -1,22 +0,0 @@
import { useCallback, useEffect, useRef } from "react";
// credits: https://github.com/streamich/react-use/blob/master/src/useMountedState.ts
// jsdoc generated by chat-gpt :)
/**
* A custom React hook that returns a function to check if the component is mounted.
* @returns {function(): boolean} A function that returns `true` if the component is mounted and `false` otherwise.
*/
export default function useMountedState(): () => boolean {
const mountedRef = useRef<boolean>(false);
const get = useCallback(() => mountedRef.current, []);
useEffect(() => {
mountedRef.current = true;
return () => {
mountedRef.current = false;
};
}, []);
return get;
}
-4
View File
@@ -4,15 +4,12 @@ import { useEffect } from "react";
import { useEmbedTheme } from "@calcom/embed-core/embed-iframe";
import type { Maybe } from "@calcom/trpc/server";
import useMountedState from "./useMountedState";
// makes sure the ui doesn't flash
export default function useTheme(theme?: Maybe<string>) {
let currentTheme: Maybe<string> = theme || "system";
const { resolvedTheme, setTheme, forcedTheme, theme: activeTheme } = useNextTheme();
const embedTheme = useEmbedTheme();
const isMounted = useMountedState();
// Embed UI configuration takes more precedence over App Configuration
currentTheme = embedTheme || theme;
@@ -28,6 +25,5 @@ export default function useTheme(theme?: Maybe<string>) {
setTheme,
forcedTheme,
activeTheme,
isReady: isMounted(),
};
}