3.3.0 • Published 3 years ago

react-simple-matchmedia v3.3.0

Weekly downloads
551
License
MIT
Repository
github
Last release
3 years ago

react-simple-matchmedia

npm.io install size npm.io

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:

mediavalue
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!

3.3.0

3 years ago

3.1.0

3 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.0.0

5 years ago