mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
avoid flash of light theme when using system color scheme
This commit is contained in:
@@ -1,4 +1,20 @@
|
|||||||
import { useComputedColorScheme } from "@mantine/core"
|
|
||||||
|
|
||||||
// the color scheme to use to render components
|
// the color scheme to use to render components
|
||||||
export const useColorScheme = () => useComputedColorScheme("light")
|
import { useMantineColorScheme } from "@mantine/core"
|
||||||
|
import { useMediaQuery } from "@mantine/hooks"
|
||||||
|
|
||||||
|
export const useColorScheme = () => {
|
||||||
|
const systemColorScheme = useMediaQuery(
|
||||||
|
"(prefers-color-scheme: dark)",
|
||||||
|
// passing undefined will use window.matchMedia(query) as default value
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
// get initial value synchronously and not in useEffect to avoid flash of light theme
|
||||||
|
getInitialValueInEffect: false,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
? "dark"
|
||||||
|
: "light"
|
||||||
|
|
||||||
|
const { colorScheme } = useMantineColorScheme()
|
||||||
|
return colorScheme === "auto" ? systemColorScheme : colorScheme
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user