Skip to content

Commit 630f5c2

Browse files
committed
fix(hidden): stabilize onlyKey and remove eslint suppression
Signed-off-by: Sbragul26 <sbragul26@gmail.com>
1 parent 9f7eeaf commit 630f5c2

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/base/Hidden/Hidden.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +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 ?? '';
42+
const onlyKey = Array.isArray(only) ? [...only].sort().join(',') : only ?? '';
4543

4644
const mediaQuery = useMemo(() => {
47-
const onlyValues = Array.isArray(only) ? only : only ? [only] : [];
45+
const onlyValues = onlyKey ? (onlyKey.split(',') as Breakpoint[]) : [];
4846
const upProps: Record<Breakpoint, boolean> = { xs: xsUp, sm: smUp, md: mdUp, lg: lgUp, xl: xlUp };
4947
const downProps: Record<Breakpoint, boolean> = { xs: xsDown, sm: smDown, md: mdDown, lg: lgDown, xl: xlDown };
5048
const conditions: string[] = [];
@@ -62,7 +60,6 @@ export const Hidden = ({
6260
}
6361

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

6865
const matches = useMediaQuery(mediaQuery);

0 commit comments

Comments
 (0)