🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

react-micro-match-media

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-micro-match-media

> zero dependencies, ~1kb render prop wrapper of window.matchMedia

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

react-micro-match-media

zero dependencies, ~1kb render prop wrapper of window.matchMedia

Instalation

$ npm install --save react-micro-match-media

Peer dependencies

This package expect react@^16.3.0 as a peer dependency.

Usage

You just pass in the query that you want to be listening and render your components accordingly.

import React, { Component } from 'react'
import MatchMedia from 'react-micro-match-media'

const App = () => (
  <MatchMedia query={`(max-width: 600px)`}>
    {matches => {
      if (matches) return 'will be rendered if viewport is <= 600'
      return 'will be rendered if viewport is > 600'
    }}
  </MatchMedia>
)

Smart usage

You can also do things like:

import React, { Component } from 'react'
import MatchMedia from 'react-micro-match-media'

const Portrait = ({ children, ...props }) => (
  <MatchMedia {...props} query={`(orientation: portrait)`}>
    {isPortrait => (isPortrait ? children : null)}
  </MatchMedia>
)

const App = () => (
  <Portrait>will render only if orientation is portrait</Portrait>
)

Keywords

react

FAQs

Package last updated on 18 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts