Skip to content

How to use useMediaQuery with the same set of breakpoints efficiently across many components #1270

Closed Answered by kdevan
kdevan asked this question in Q&A
Discussion options

You must be logged in to vote

Using the first method is performing well for me so far. I'll update if I run into anything as I add to more components. The component looks something like this:

import { useMediaQuery } from '@react-hookz/web/esm/useMediaQuery';

export function useScreenBreakpoint() {
  const xxs = useMediaQuery('only screen and (max-width : 320px)');
  const xs = useMediaQuery('only screen and (min-width : 321px) and (max-width : 375px)');
  const sm = useMediaQuery('only screen and (min-width : 376px) and (max-width : 640px)');
  const md = useMediaQuery('only screen and (min-width : 641px) and (max-width : 768px)');
  const lg = useMediaQuery('only screen and (min-width : 769px) and (max-width : 1024…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by kdevan
Comment options

You must be logged in to vote
2 replies
@xobotyi
Comment options

@kdevan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants