Skip to content

Commit b1ad014

Browse files
committed
revalidate on theme pref change
Closes #163
1 parent 1de6c83 commit b1ad014

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

app/utils/client-hints.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
import * as React from 'react'
66
import { useRequestInfo } from './request-info.ts'
7+
import { useRevalidator } from '@remix-run/react'
78

89
export const clientHints = {
910
theme: {
@@ -77,18 +78,20 @@ export function useHints() {
7778
* inaccurate value.
7879
*/
7980
export function ClientHintCheck({ nonce }: { nonce: string }) {
81+
const { revalidate } = useRevalidator()
8082
React.useEffect(() => {
8183
const themeQuery = window.matchMedia('(prefers-color-scheme: dark)')
8284
function handleThemeChange() {
8385
document.cookie = `${clientHints.theme.cookieName}=${
8486
themeQuery.matches ? 'dark' : 'light'
8587
}`
88+
revalidate()
8689
}
8790
themeQuery.addEventListener('change', handleThemeChange)
8891
return () => {
8992
themeQuery.removeEventListener('change', handleThemeChange)
9093
}
91-
}, [])
94+
}, [revalidate])
9295

9396
return (
9497
<script

0 commit comments

Comments
 (0)