File size: 935 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/**
* This file contains utilities for using client hints for user preference which
* are needed by the server, but are only known by the browser.
*/
import { useRevalidator } from '@remix-run/react'
import * as React from 'react'
import {
getHintUtils,
subscribeToSchemeChange,
themeClientHint,
} from '../../helpers/client-hints'
const hintsUtils = getHintUtils({
theme: themeClientHint,
})
export const { getHints } = hintsUtils
/**
* @returns inline script element that checks for client hints and sets cookies
* if they are not set then reloads the page if any cookie was set to an
* inaccurate value.
*/
export function ClientHintCheck() {
const { revalidate } = useRevalidator()
React.useEffect(
() => subscribeToSchemeChange(() => revalidate()),
[revalidate]
)
return (
<script
dangerouslySetInnerHTML={{
__html: hintsUtils.getClientHintCheckScript(),
}}
/>
)
}
|