Reactopia
BrowseDiscoverSVG toolsAIChangelogAboutContact
BrowseDiscoverSVG toolsAI
Created by

Yash Mahajan


Reactopia

Open React tooling: components, SVG animation, and a growing directory. Built by Yash Mahajan.

Product

  • Components
  • Discover
  • SVG tools
  • AI direction

Legal

  • Privacy Policy
  • Terms of Use
  • Cookie Policy
  • License
  • Credits
  • Contact

Project

  • About
  • Changelog
  • GitHub
  • X

© 2026 Reactopia. All rights reserved.

PrivacyTermsCookies

Getting Started

IntroductionContributing

Components

SeparatorUiButtonBadgeStackUiInputIn devUiSelectIn devUiTextareaIn dev

Hooks

useDebounceuseLocalStorageuseMediaQueryuseMounted

Utilities

cngroupBysleep
Components
useMediaQuery

useMediaQuery

Subscribe to a CSS media query in React.

LivehookReact, WebUpdated 2026-10-07MIT LicenseSource on GitHubReport Issue
Dependencies:npm install react
useLocalStorageuseMounted

Introduction

Subscribe to a CSS media query and re-render when it changes. Useful for responsive layouts without duplicating breakpoint logic in CSS only.

Platform: React (browser). Dependencies: react only.

Hook

import { useEffect, useState } from "react";
export function useMediaQuery(query: string): boolean {
const getMatches = () =>
typeof window !== "undefined" ? window.matchMedia(query).matches : false;
const [matches, setMatches] = useState(getMatches);
useEffect(() => {
const mql = window.matchMedia(query);
const onChange = () => setMatches(mql.matches);
onChange();
mql.addEventListener("change", onChange);
return () => mql.removeEventListener("change", onChange);
}, [query]);
return matches;
}

Example

tsx
const isMdUp = useMediaQuery("(min-width: 768px)");

Footer

Match the same breakpoints you use in Tailwind (sm, md, lg) for consistent behavior.