1. match-media-mock
server side compatible replacement for Window.matchMedia()
match-media-mock
Package: match-media-mock
Created by: azazdeaz
Last modified: Sun, 19 Jun 2022 16:29:32 GMT
Version: 0.1.1
License: MIT
Downloads: 36,466
Repository: https://github.com/azazdeaz/match-media-mock

Install

npm install match-media-mock
yarn add match-media-mock

MatchMediaMock

Build Status
npm

Simple server-side compatible substitution for Window.matchMedia() based on css-mediaquery.
Designed for use with Radium.

Basic usage

 var matchMediaMock = require('match-media-mock').create()
matchMediaMock.setConfig({type: 'screen', width: 1200})

matchMediaMock('(max-width: 991px)').matches // false
matchMediaMock('(max-width: 1240px)').matches // true

var mediaQueryList = matchMediaMock(mediaQuery)
mediaQueryList.addListener(listener)
mediaQueryList.removeListener(listener)
mediaQueryList.callListeners()

For more details about matching check out css-mediaquery!

Example usage with Radium

 var Radium = require('radium')
var matchMediaMock = require('match-media-mock').create()
Radium.config.setMatchMedia(matchMediaMock)

app.get('/app/:width/:height', function(req, res) {
  matchMediaMock.setConfig({
    type: 'screen',
    width: req.params.width,
    height: req.params.height
  })
  var html = React.renderToString(<RadiumApp/>)
  res.end(html)
})

For more details see the Radium docs

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code