# 🔫 ReactPonsive
> Responsive components and Hooks ⚒ for your favorite framework ⚛️ [http://jmlweb.github.io/reactponsive](http://jmlweb.github.io/reactponsive)
[![Last Commit][last-commit-badge]][last-commit]
[![Travis][build-badge]][build]
[![npm package][npm-badge]][npm]
[![Coveralls][coveralls-badge]][coveralls]
[](https://lgtm.com/projects/g/jmlweb/reactponsive/context:javascript)
[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
[![Tweet][twitter-badge]][twitter]
[last-commit-badge]: https://img.shields.io/github/last-commit/jmlweb/reactponsive.svg
[last-commit]: https://github.com/jmlweb/reactponsive
[build-badge]: https://img.shields.io/travis/jmlweb/reactponsive/master.png?style=flat-square
[build]: https://travis-ci.org/jmlweb/reactponsive
[npm-badge]: https://img.shields.io/npm/v/reactponsive.png?style=flat-square
[npm]: https://www.npmjs.org/package/reactponsive
[coveralls-badge]: https://img.shields.io/coveralls/jmlweb/reactponsive/master.png?style=flat-square
[coveralls]: https://coveralls.io/github/jmlweb/reactponsive
[github-watch-badge]: https://img.shields.io/github/watchers/jmlweb/reactponsive.svg?style=social
[github-watch]: https://github.com/jmlweb/reactponsive/watchers
[github-star-badge]: https://img.shields.io/github/stars/jmlweb/reactponsive.svg?style=social
[github-star]: https://github.com/jmlweb/reactponsive/stargazers
[twitter]: https://twitter.com/intent/tweet?text=Reactponsive:%20Responsive%20hooks%20and%20components%20for%20React%20⚛️:%20https%3A%2F%2Fgithub.com%2Fjmlweb%2Freactponsive
[twitter-badge]: https://img.shields.io/twitter/url/https/github.com/testing-library/dom-testing-library.svg?style=social
- [Principles](#Principles)
- [Installation](#Installation)
- [Requirements](#Requirements)
- [API](#API)
- [Provider](#Provider)
- [useInfo](#useInfo)
- [useToggler](#useToggler)
- [useMapper](#useMapper)
- [useFilter](#useFilter)
- [Toggler](#Toggler)
- [Mapper](#Mapper)
- [Filter](#Filter)
- [useAlias](#useAlias)
## Principles
- Intended for complex interfaces **where the use of media queries in CSS is not enough** (Displaying different headers on mobile/desktop, enhancing accesibility in your components if some flag is active, displaying charts only on desktop sizes...).
- Works with **native MatchMedia API** and receives **[valid Media Query Strings](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries)** as arguments.
- Supports the use of **"alias"** (`{ tablet: '(min-width: 768px)' }`).
- Is **fast** and performant, and **only updates** the connected components **when needed**.
- Includes a **Jest mock for MatchMedia** API which supports updating the breakpoints matches.
## Installation
```sh
npm install reactponsive
#or
yarn add reactponsive
```
## Requirements
- ReactPonsive **works only with hooks** for performance reasons, so you will need **React >= 16.8** (or any older experimental version supporting hooks)
- You will also need **@testing-library/react-hooks** and **react-test-renderer**
## API
### Provider
This is where all the magic take place. **You must include this component before using the rest of the components and hooks.**
The use of `alias` is supported with the same property to keep your mind sane 😸.
This property is an object, where each key refers to the alias name, and the value to a valid [media query string](https://developer.mozilla.org/es/docs/CSS/Media_queries).
```jsx
import { Provider } from "reactponsive";
import MyAppComponent from "./MyAppComponent";
const alias = {
tablet: "(min-width: 768px)",
desktop: "(min-width: 1024px)",
hd: "(-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi)",
darkMode: "(prefers-color-scheme: dark)",
supportsHover: "(hover: hover)",
noMotion: "(prefers-reduced-motion: reduce)"
};
const App = () => (