From ce780fb8971a129371e39272e30ce727aad9584d Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Mon, 17 Feb 2025 11:29:02 +0500 Subject: [PATCH] mobile: fix error set state in render --- apps/mobile/app/app.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/mobile/app/app.tsx b/apps/mobile/app/app.tsx index 091d618c7..4fa4e2d71 100644 --- a/apps/mobile/app/app.tsx +++ b/apps/mobile/app/app.tsx @@ -127,13 +127,15 @@ export const withTheme = (Element: (props: any) => JSX.Element) => { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - const nextTheme = colorScheme === "dark" ? darkTheme : lightTheme; - if (JSON.stringify(nextTheme) !== JSON.stringify(currTheme)) { - useThemeEngineStore - .getState() - .setTheme(colorScheme === "dark" ? darkTheme : lightTheme); - currTheme = nextTheme; - } + useEffect(() => { + const nextTheme = colorScheme === "dark" ? darkTheme : lightTheme; + if (JSON.stringify(nextTheme) !== JSON.stringify(currTheme)) { + useThemeEngineStore + .getState() + .setTheme(colorScheme === "dark" ? darkTheme : lightTheme); + currTheme = nextTheme; + } + }, [colorScheme, darkTheme, lightTheme]); return (