# react-mql

> React Component, HOC, and Redux Reducer to manage mediaQueries.

Latest version **0.0.2** (published 2016-09-22) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2016-09-22 |
| First published | 2016-09-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Doug Miller |
| Maintainers | dougmiller |

## Links

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

## Recent versions

- 0.0.2 (latest) — 2016-09-22
- 0.0.1 — 2016-09-21

## README

# react-mql

React Component, HOC, and Redux Reducer to manage mediaQueries.

## Installation

```
npm install --save react-mql
```

## What's included

#### `<MatchMedia media={ [] }/>{ (matchMedia) => {} }</MatchMedia>`

A React component that takes a `media` prop and a function for `children` the function is called with the mediaQueries and if the match the query.

#### `withMatchMedia(mediaQuery [, mediaQuery])(Component)`

An HOC that will pass the status of mediaQueries as a prop provided to the wrapped component.

#### `createMatchMediaReducer(mediaQuery [, mediaQuery])`

Creates a redux store for the provided mediaQueries.

#### `syncMatchMediaWithStore(reducerKey, reduxStore)`

Monitors the mediaQueries from the matchMediaReducer

## MatchMedia Example

```js
import React, { Component } from 'react'
import { MatchMedia } from 'react-mql';
import { minWidthSmall, minWidthMedium } from './styles/breakpoints'; //minWidthSmall: ('min-width: 500px') minWidthMedium: ('min-width: 800px')

const MatchMediaExample = (props) => (
  <div>
    <MatchMedia media={[ minWidthSmall, minWidthMedium ]}>
      { (matchesMedia) => ( //matchMedia: { "('min-width: 500px')": true, "('min-width: 800px')": true }
        <div>
          { matchMedia[minWidthSmall] && <div>I show match min-width of 500px</div> }
          { matchMedia[minWidthMedium] && <div>I show match min-width of 800px</div> }
        </div>
      ) }
    </MatchMedia>
  </div>
);
export default MatchMediaExample;
```

## withMatchMedia Example

```js
import React, { Component } from 'react'
import { withMatchMedia } from 'react-mql';
import { minWidthSmall, minWidthMedium } from './styles/breakpoints'; //minWidthSmall: ('min-width: 500px') minWidthMedium: ('min-width: 800px')

const withSmallAndMedium(minWidthSmall, minWidthMedium);

const MatchMediaExample = (props) => ( // props.matchesMedia: { "('min-width: 500px')": true, "('min-width: 800px')": true }
  <div></div>
);
export default withSmallAndMedium(MatchMediaExample);
```

## Redux Example

```js

import React from 'react'
import ReactDOM from 'react-dom'
import { createMatchMediaReducer, syncMatchMediaWithStore } from 'react-mql'
import { createStore, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import { minWidthSmall, minWidthMedium } from './styles/breakpoints'; //minWidthSmall: ('min-width: 500px') minWidthMedium: ('min-width: 800px')
import Application from './Application';
import reducers from './reducers'

// Add the reducer to your store on the `matchesMedia` key
const store = createStore(
  combineReducers({
    ...reducers,
    matchesMedia: createMatchMediaReducer(minWidthSmall, minWidthMedium)
  })
);

// Start listening on the mediaQueries and dispatch events on changes.
syncMatchMediaWithStore('matchesMedia', store);

ReactDOM.render(
  <Provider store={store}>
    <Application />
  </Provider>,
  document.getElementById('mount')
);
```

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