Skip to content

Commit 9f7eeaf

Browse files
committed
fix(hidden): stabilize useMemo dependency for only prop
Signed-off-by: Sbragul26 <sbragul26@gmail.com>
1 parent c543d51 commit 9f7eeaf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/base/Hidden/Hidden.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export const Hidden = ({
3939
}: HiddenProps) => {
4040
const theme = useTheme();
4141

42+
// Serialize `only` to a stable string so that array literals passed as props
43+
// (e.g. only={['xs', 'md']}) don't defeat memoization due to new references.
44+
const onlyKey = Array.isArray(only) ? only.join(',') : only ?? '';
45+
4246
const mediaQuery = useMemo(() => {
4347
const onlyValues = Array.isArray(only) ? only : only ? [only] : [];
4448
const upProps: Record<Breakpoint, boolean> = { xs: xsUp, sm: smUp, md: mdUp, lg: lgUp, xl: xlUp };
@@ -58,7 +62,8 @@ export const Hidden = ({
5862
}
5963

6064
return conditions.length > 0 ? `@media ${conditions.join(', ')}` : '@media not all';
61-
}, [only, xsUp, smUp, mdUp, lgUp, xlUp, xsDown, smDown, mdDown, lgDown, xlDown, theme.breakpoints]);
65+
// eslint-disable-next-line react-hooks/exhaustive-deps
66+
}, [onlyKey, xsUp, smUp, mdUp, lgUp, xlUp, xsDown, smDown, mdDown, lgDown, xlDown, theme.breakpoints]);
6267

6368
const matches = useMediaQuery(mediaQuery);
6469

0 commit comments

Comments
 (0)