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