# @hocs/with-match-media-props

> CSS Media Queries HOC for React

Latest version **0.4.0** (published 2018-07-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @hocs/with-match-media-props
pnpm add @hocs/with-match-media-props
yarn add @hocs/with-match-media-props
bun add @hocs/with-match-media-props
```

## 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.4.0 |
| Published | 2018-07-15 |
| First published | 2017-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2039 |
| Author | Kir Belevich |
| Maintainers | hocs |
| Keywords | react, hoc, recompose, matchmedia, mediaqueries |

## Links

- npm: https://www.npmjs.com/package/@hocs/with-match-media-props
- Repository: https://github.com/deepsweet/hocs
- Homepage: https://github.com/deepsweet/hocs#readme
- Issues: https://github.com/deepsweet/hocs/issues
- npm.io page: https://npm.io/package/@hocs/with-match-media-props

## Dependencies (2)

- [json2mq](https://npm.io/package/json2mq.md) ^0.2.0
- [react-display-name](https://npm.io/package/react-display-name.md) ^0.2.4

## 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.4.0 (latest) — 2018-07-15
- 0.3.0 — 2017-10-09
- 0.2.0 — 2017-08-19
- 0.1.2 — 2017-08-05
- 0.1.1 — 2017-08-04
- 0.1.0 — 2017-08-04

## README

# :left_right_arrow: with-match-media-props

[![npm](https://img.shields.io/npm/v/@hocs/with-match-media-props.svg?style=flat-square)](https://www.npmjs.com/package/@hocs/with-match-media-props) [![ci](https://img.shields.io/travis/deepsweet/hocs/master.svg?style=flat-square)](https://travis-ci.org/deepsweet/hocs) [![coverage](https://img.shields.io/codecov/c/github/deepsweet/hocs/master.svg?style=flat-square)](https://codecov.io/github/deepsweet/hocs) [![deps](https://david-dm.org/deepsweet/hocs.svg?path=packages/with-match-media-props&style=flat-square)](https://david-dm.org/deepsweet/hocs?path=packages/with-match-media-props)

Part of a [collection](https://github.com/deepsweet/hocs) of Higher-Order Components for React, especially useful with [Recompose](https://github.com/acdlite/recompose).

Dynamically map [CSS Media Queries](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries) matches to boolean props using [`window.matchMedia()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia) ([Can I use?](https://caniuse.com/#search=matchmedia)).

## Install

```
yarn add @hocs/with-match-media-props
```

## Usage

```js
withMatchMediaProps(
  mediaMatchers: {
    [propName: string]: Object
  }
): HigherOrderComponent
```

Where media matcher value is [json2mq](https://github.com/akiran/json2mq) object.
```js
import React from 'react';
import withMatchMediaProps from '@hocs/with-match-media-props';

const Demo = (props) => (
  <h1>props: {JSON.stringify(props)}</h1>
  // props: {"isSmallScreen":false,"isRetina":true}
);

export default withMatchMediaProps({
  isSmallScreen: {
    maxWidth: 500
  },
  isHighDpiScreen: {
    minResolution: '192dpi'
  }
})(Demo);
```

:tv: [Check out live demo](https://codesandbox.io/s/lpq4qr3o29).

## Notes

* You still might need a polyfill but I can't find any.
* Target Component will be just passed through on unsupported platforms (i.e. `global.matchMedia` is not a function) like IE9, JSDOM (so Jest as well) or with Server-Side Rendering. This means that there will be no boolean props (i.e. `undefined`) which might be expected, but you can take care of it using Recompose [`defaultProps`](https://github.com/acdlite/recompose/blob/master/docs/API.md#defaultprops) HOC if it's really necessary.

---
_Source: https://npm.io/package/@hocs/with-match-media-props · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
