traintrape-moi/client/hooks/useColorScheme.web.ts

22 lines
472 B
TypeScript
Raw Normal View History

2024-12-07 10:24:41 +01:00
import { useEffect, useState } from 'react'
import { useColorScheme as useRNColorScheme } from 'react-native'
2024-12-01 12:29:47 +01:00
/**
* To support static rendering, this value needs to be re-calculated on the client side for web
*/
export function useColorScheme() {
2024-12-07 10:24:41 +01:00
const [hasHydrated, setHasHydrated] = useState(false)
2024-12-01 12:29:47 +01:00
useEffect(() => {
2024-12-07 10:24:41 +01:00
setHasHydrated(true)
}, [])
2024-12-01 12:29:47 +01:00
2024-12-07 10:24:41 +01:00
const colorScheme = useRNColorScheme()
2024-12-01 12:29:47 +01:00
if (hasHydrated) {
2024-12-07 10:24:41 +01:00
return colorScheme
2024-12-01 12:29:47 +01:00
}
2024-12-07 10:24:41 +01:00
return 'light'
2024-12-01 12:29:47 +01:00
}