
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-media-universal
Advanced tools
react-media-universal is a CSS media query component for React, for use with server side rendering.
It is based on react-media and uses the same API, with the addition of a <MediaProvider> component. It solves problems when hydrating a server side rendered app that uses <Media> components for conditional rendering.
Using npm:
$ npm install --save react-media-universal
Then, use the <MediaProvider> and <Media> component as you would anything else:
// using ES modules
import Media, { MediaProvider } from "react-media-universal";
// using CommonJS modules
var Media = require("react-media-universal");
var MediaProvider = require("react-media-universal").MediaProvider;
The UMD build is also available on unpkg:
<script src="https://unpkg.com/react-media-universal/umd/react-media-universal.min.js"></script>
You can find the library on window.ReactMediaUniversal.
Make sure to wrap your entire tree in the <MediaProvider> component for the hydration from server side rendering to work properly.
For the API of the <Media> component, see the docs for react-media.
import React from "react";
import Media, { MediaProvider } from "react-media-universal";
class App extends React.Component {
render() {
return (
<MediaProvider>
<div>
<Media query="(max-width: 599px)">
{matches =>
matches ? (
<p>The document is less than 600px wide.</p>
) : (
<p>The document is at least 600px wide.</p>
)
}
</Media>
</div>
</MediaProvider>
);
}
}
If you render a <Media> component on the server, it always matches. To change this behaviour, use the defaultMatches prop:
import React from "react";
import Media, { MediaProvider } from "react-media-universal";
class App extends React.Component {
render() {
return (
<MediaProvider>
<div>
<Media
query="(max-width: 599px)"
defaultMatches={false}
render={() => <p>This will not be rendered on the server, nor on the first render pass on client, even if the screen is less than 600px wide.</p>}
/>
</div>
</MediaProvider>
);
}
}
react-media-universal is developed and maintained by Hyperlab. If you're intrested in this library, or the other things we do, please send us an e-mail!
FAQs
Universal CSS media queries for React
We found that react-media-universal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.