> zero dependencies, ~1kb render prop wrapper of window.matchMedia
npm install react-micro-match-media> zero dependencies, ~1kb render prop wrapper of window.matchMedia
``bash`
$ npm install --save react-micro-match-media
This package expect react@^16.3.0 as a peer dependency.
You just pass in the query that you want to be listening and render your components accordingly.
`js
import React, { Component } from 'react'
import MatchMedia from 'react-micro-match-media'
const App = () => (
}>
{matches => {
if (matches) return 'will be rendered if viewport is <= 600'
return 'will be rendered if viewport is > 600'
}}
)
`
You can also do things like:
`js
import React, { Component } from 'react'
import MatchMedia from 'react-micro-match-media'
const Portrait = ({ children, ...props }) => (
}>
{isPortrait => (isPortrait ? children : null)}
)
const App = () => (
)
``