From a528bd94a6e8e25010ae26a305550b211df0ddc6 Mon Sep 17 00:00:00 2001 From: polwex Date: Tue, 15 Jul 2025 17:20:58 +0700 Subject: Initial commit Generated by create-expo 3.4.3. --- hooks/useColorScheme.web.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 hooks/useColorScheme.web.ts (limited to 'hooks/useColorScheme.web.ts') diff --git a/hooks/useColorScheme.web.ts b/hooks/useColorScheme.web.ts new file mode 100644 index 0000000..7eb1c1b --- /dev/null +++ b/hooks/useColorScheme.web.ts @@ -0,0 +1,21 @@ +import { useEffect, useState } from 'react'; +import { useColorScheme as useRNColorScheme } from 'react-native'; + +/** + * To support static rendering, this value needs to be re-calculated on the client side for web + */ +export function useColorScheme() { + const [hasHydrated, setHasHydrated] = useState(false); + + useEffect(() => { + setHasHydrated(true); + }, []); + + const colorScheme = useRNColorScheme(); + + if (hasHydrated) { + return colorScheme; + } + + return 'light'; +} -- cgit v1.2.3