# react-media-context

> React component to provide media query matches in context

Latest version **1.0.0** (published 2016-06-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-media-context
pnpm add react-media-context
yarn add react-media-context
bun add react-media-context
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-06-19 |
| First published | 2016-06-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Brent Jackson |
| Maintainers | jxnblk |
| Keywords | react, react-component, media-queries, match-media, responsive |

## Links

- npm: https://www.npmjs.com/package/react-media-context
- npm.io page: https://npm.io/package/react-media-context

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.13.1

## 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

- 1.0.0 (latest) — 2016-06-19
- 2.0.0-0 (next) — 2017-10-30

## README

# react-media-context

React higher-order component (HOC) to provide context for the currently matched media query.

## Getting Started

```sh
npm i -S react-media-context
```

## Usage

```js
const Title = (props, context) => {
  const { media } = context
  let fontSize = 32
  if (media.indexOf('large') > -1) {
    fontSize = 64
  }

  const style = {
    fontSize
  }

  return (
    <h1 style={style}>
      Responsive Heading
    </h1>
  )
}

Title.contextTypes = {
  media: React.PropTypes.array
}

class App extends React.Component {
  render () {
    <MediaContext>
      <Title />
    </MediaContext>
  }
}
```

## How is this different from *x*?

Most other responsive React HOCs tend to work on the principle of *showing and hiding* children based on media queries. With this component, you can alter styling and functionality of components responsively.

This could be handy for:
- Changing font sizes based on the viewport width
- Changing margin or padding
- Grid systems
- Dramatically altering page layout
- Using different routing flows
- Changing image sources based on pixel density (but, srcset is probably a better option)

## Props

- `queries` (Object) - Media queries to match against on window resize

```js
// Default
{
  'xsmall': 'screen and (max-width: 40em)',
  'small': 'screen and (min-width: 40em)',
  'medium': 'screen and (min-width: 52em)',
  'large': 'screen and (min-width: 64em)'
}
```

MIT License

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