Skip to content

Commit

Permalink
Add useMediaQuery printing console warning
Browse files Browse the repository at this point in the history
- Added warning for using `print` query
  • Loading branch information
good-jinu committed Dec 17, 2024
1 parent 67f2708 commit c1fbb29
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/mui-system/src/useMediaQuery/useMediaQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ export function unstable_createUseMediaQuery(params: { themeId?: string } = {})
let query = typeof queryInput === 'function' ? queryInput(theme) : queryInput;
query = query.replace(/^@media( ?)/m, '');

if (query.includes('print')) {
console.warn(
[
`MUI: You have provided a query \`print\` for the useMediaQuery.`,
'Using the print media query to modify print styles might lead to unexpected results.',
'Consider using the `displayPrint` field in the `sx` prop instead.',
].join('\n'),
);
}

const useMediaQueryImplementation =
maybeReactUseSyncExternalStore !== undefined ? useMediaQueryNew : useMediaQueryOld;
const match = useMediaQueryImplementation(
Expand Down

0 comments on commit c1fbb29

Please sign in to comment.