Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-simple-matchmedia

egdbear5.7kMIT3.3.0

React component used for matching media queries

window.matchMedia, react-component, react, react-simple-matchmedia, matchmedia, useWindowMedia

readme

react-simple-matchmedia

install size

React hook used for matching media queries.
It uses browser's window.matchMedia.
With SSR support :rocket:

Install

$ yarn add react-simple-matchmedia

or

$ npm i react-simple-matchmedia

Usage

Edit hopeful-jennings-cho5q

Pre-defined media queries:

media value
phone (min-width: 320px) and (max-width: 568px)
tablet (min-width : 768px) and (max-width : 1024px)
desktop (min-width : 1224px)

With pre-defined query:

import useReactSimpleMatchMedia from 'react-simple-matchmedia'

const MediaQueryComponent = () => {
  const matched = useReactSimpleMatchMedia('phone');

  return (
    <Fragment>
      { matched && <div>I am only visible and rendered in DOM on phone screen!</div>}
    </Fragment>
  );
}

With custom queries:

import useReactSimpleMatchMedia from 'react-simple-matchmedia'

const MediaQueryComponent = () => {
  const matched = useReactSimpleMatchMedia('(min-width: 600) and (max-width: 1200px)');

  return (
    <Fragment>
      { matched && <div>I am only visible and rendered in DOM between 600px and 1200px</div>}
    </Fragment>
  );
}

#

Enjoy and have fun!

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.3.0 (2021-10-21)

Features