# react-matchqueries

> Library to control the design of your application using media queries

Latest version **0.0.2** (published 2018-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-matchqueries
pnpm add react-matchqueries
yarn add react-matchqueries
bun add react-matchqueries
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2018-10-14 |
| First published | 2018-10-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 15.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Abu Shamsutdinov |
| Maintainers | yakotika |
| Keywords | react, matchmedia, media-queries, match-media, responsive |

## Links

- npm: https://www.npmjs.com/package/react-matchqueries
- Repository: https://github.com/yakotika/react-matchqueries
- Homepage: https://github.com/yakotika/react-matchqueries#readme
- Issues: https://github.com/yakotika/react-matchqueries/issues
- npm.io page: https://npm.io/package/react-matchqueries

## Dependencies (3)

- [matchmedia](https://npm.io/package/matchmedia.md) ^0.1.2
- [shallowequal](https://npm.io/package/shallowequal.md) ^1.1.0
- [css-mediaquery](https://npm.io/package/css-mediaquery.md) ^0.1.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2018-10-14
- 0.0.1 — 2018-10-14
- 0.0.0-beta.1 — 2018-10-14
- 0.0.0-beta.0 — 2018-10-14

## README

# react-matchqueries

[![npm version](https://badge.fury.io/js/react-matchqueries.svg)](https://badge.fury.io/js/react-matchqueries) ![](https://img.shields.io/npm/dm/react-matchqueries.svg)

> Library to control the design of your application using media queries 🔥

## Install

Via [NPM](https://docs.npmjs.com/):
```bash
npm install react-matchqueries --save
```

Via [Yarn](https://yarnpkg.com/en/):
```bash
yarn add react-matchqueries
```

## Usage

### `MatchQueriesProvider`

```javascript
import { MatchQueriesProvider } from 'react-matchqueries';

const queries = {
    isMobile: 'screen and (max-width: 767px)',
    isTablet: 'screen and (min-width: 768px) and (max-width: 1023px)',
    isDekstopS: 'screen and (min-width: 1024px) and (max-width: 1365px)',
    isDekstop: 'screen and (min-width: 1366px) and (max-width: 1440px)',
    isDekstopL: 'screen and (min-width: 1441px)'
}

export const Route = (props) =>  (
  <MatchQueriesProvider queries={queries}>
    <MyApp />
  </MatchQueriesProvider>
);

```

### `MatchQueriesConsumer`

```javascript
import { MatchQueriesConsumer } from 'react-matchqueries';

export const MyApp = () => (
  <MatchQueriesConsumer>
    {({ isDekstopS, isDekstop, isDekstopL, isTablet, isMobile }) => (
      <>
        {(isDekstopS || isDekstop || isDekstopL) && <p>Desktop View</p>}
        {(isTablet || isMobile) && <p>Tablet and Mobile View</p>}
      </>
    )}
  </MatchQueriesConsumer>
);


```

### Server Side Rendering

You can pass in media features from your server, all supported values can be found [here](https://www.w3.org/TR/css3-mediaqueries/#media1).

**Usage (matches mobile screen during SSR):**
```javascript
import { MatchQueriesProvider } from 'react-matchqueries';

const Route = () => {
  const values = {
    width: 300,
    type: 'screen',
  };

  return (
    <MatchQueriesProvider values={values}>
      <MyApp />
    </MatchQueriesProvider>
  );
};
```

#### React 16 ReactDOM.hydrate

It's very important to realise a server client mismatch is dangerous when using hydrate in React 16, ReactDOM.hydrate
can cause very [strange](https://github.com/facebook/react/issues/10591) html on the client if there is a mismatch.
To mitigate this we use the two-pass rendering technique mentioned in the React [docs](https://reactjs.org/docs/react-dom.html#hydrate).
We render on the client in the first pass using `values` with `css-mediaquery` used on the server, then we use the `matchmedia`
to get it's actual dimensions and render again if it causes different query results. This means there should be no React
server/client mismatch warning in your console and you can safely use hydrate. As a result of above, if you are server side rendering and using `ReactDOM.hydrate` you must supply `MatchQueriesConsumer` a `values` prop.

---
_Source: https://npm.io/package/react-matchqueries · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
