Skip to content

ds-pack/use-media

Repository files navigation

@ds-pack/use-media

A small stateful hook for using the window.matchMedia API within a React component.

Installation:

yarn add @ds-pack/use-media

Usage:

import useMedia from '@ds-pack/use-media'

let mediaQuery = '(min-width: 100px)'

function Component() {
  let matches = useMedia(mediaQuery)

  return matches ? <div /> : null
}

Tools:

  • Typescript
  • Babel
  • Jest