streamich/use-media is one of the open-source repositories TopGit tracks, currently at 524 stars, written primarily in TypeScript. useMedia React hook to track CSS media query state
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
useMedia React sensor hook that tracks state of a CSS media query.
Install
You can install use-media with npm
npm install --save use-media
or with yarn
yarn add use-media
Usage
With useEffect
import useMedia from 'use-media';
// Alternatively, you can import as:
// import {useMedia} from 'use-media';
const Demo = () => {
// Accepts an object of features to test
const isWide = useMedia({minWidth: '1000px'});
// Or a regular media query string
const reduceMotion = useMedia('(prefers-reduced-motion: reduce)');
return (
<div>
Screen is wide: {isWide ? '😃' : '😢'}
</div>
);
};
With useLayoutEffect
import {useMediaLayout} from 'use-media';
const Demo = () => {
// Accepts an object of features to test
const isWide = useMediaLayout({minWidth: '1000px'});
// Or a regular media query string
const reduceMotion = useMediaLayout('(prefers-reduced-motion: reduce)');
return (
<div>
Screen is wide: {isWide ? '😃' : '😢'}
</div>
);
};
Testing
Depending on your testing setup, you may need to mock window.matchMedia on components that utilize the useMedia hook. Below is an example of doing this in jest:
/test-utilities/index.ts
import {mockMediaQueryList} from 'use-media/lib/useMedia';
// Types are also exported for convienence:
// import {Effect, MediaQueryObject} from 'use-media/lib/types';
export interface MockMatchMedia {
media: string;
matches?: boolean;
}
function getMockImplementation({media, matches = false}: MockMatchMedia) {
const mql: MediaQueryList = {
...mockMediaQueryList,
media,
matches,
};
return () => mql;
}
export function jestMockMatchMedia({media, matches = false}: MockMatchMedia) {
const mockedImplementation = getMockImplementation({media, matches});
window.matchMedia = jest.fn().mockImplementation(mockedImplementation);
}
Depending on your app, you may be using the useMedia hook to register many matchMedia listeners across multiple components. It may help to elevate these listeners to Context.
TopGit's last sync did not record any GitHub topics for streamich/use-media. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on streamich/use-media?
The most recent commit recorded on streamich/use-media was 1.2 years ago, based on the GitHub push timestamp. The repository has 24 forks — one of the better signals of community interest.
How many stars does streamich/use-media have?
streamich/use-media has 524 GitHub stars — refresh the page for the live number, or check github.com/streamich/use-media. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What language is streamich/use-media written in?
streamich/use-media is written primarily in TypeScript. GitHub's language field is based on the largest share of bytes in the default branch.
Where do I read more about streamich/use-media?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/streamich/use-media is the definitive source.
Read full README in the tab above.
Curious whether use-media is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about use-media.