DEMO
Try resizing the window to observe change
min-width: 1024pxfalse
Try switching system color preference to observe change
prefers-color-scheme: darkfalse

useMediaQuery

Reactive media query hook that returns the truthy value of the media query.

Usage

import { useMediaQuery } from '@react-hooks-library/core'

function Demo() {
  const isLargeScreen = useMediaQuery('(min-width: 1024px)')
  const prefersDark = useMediaQuery('(prefers-color-scheme: dark)')
}

return (
  <>
    <div>
      {isLargeScreen ? 'The screen is large' : 'The screen is small'}
    </div>
    <div>
      {prefersDark ? 'User prefers dark mode' : 'User prefers light mode'}
    </div>
  </>
)

Type Declarations

/**
 * Reactive media query hook that returns the truthy value of the media query.
 *
 * @param {string} query
 * @returns {boolean} boolean value of the query
 *
 * @see https://react-hooks-library.vercel.app/core/useMediaQuery
 */
declare function useMediaQuery(query: string): boolean

Source

Source | Demo | Docs