Skip to content

Commit 3714548

Browse files
authored
Add warning to useResponsiveValue
1 parent 84ffeaa commit 3714548

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/react/src/hooks/useResponsiveValue.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {useMediaUnsafeSSR} from './useMediaUnsafeSSR'
2+
import {canUseDOM} from '../utils/environment'
3+
import {warning} from '../utils/warning'
24

35
// This file contains utilities for working with responsive values.
46

@@ -55,6 +57,11 @@ export function useResponsiveValue<T, F>(value: T, fallback: F): FlattenResponsi
5557
const isRegularViewport = useMediaUnsafeSSR(viewportRanges.regular, false)
5658
const isWideViewport = useMediaUnsafeSSR(viewportRanges.wide, false)
5759

60+
warning(
61+
!canUseDOM,
62+
'`useResponsiveValue` is not fully SSR compatible as it relies on `useMediaUnsafeSSR` without a `defaultState`. Using `getResponsiveAttributes` is preferred to avoid hydration mismatches.',
63+
)
64+
5865
if (isResponsiveValue(value)) {
5966
// If we've reached this line, we know that value is a responsive value
6067
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)