![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
react-native-media-query
Advanced tools
Adds support for media queries in react-native/react-native-web, :hover
for react-native-web, triggers on device orientation changes and also works with next.js static generation or server-side rendering.
yarn add react-native-media-query
or
npm install react-native-media-query --save
import StyleSheet from 'react-native-media-query';
//note that StyleSheet.create shouldn't be used here
const styles = {
example: {
backgroundColor: 'green',
'@media (max-width: 1600px)': {
backgroundColor: 'red',
},
'@media (max-width: 800px)': {
backgroundColor: 'blue',
},
}
}
// for now css media queries on web are being generated based on this ComponentIdentifier, so it shouldn't be the same in different files. Component name could be used.
const {ids, styles} = StyleSheet.create(styles, 'HomeScreen');
...
// for react-native-web 0.13+
<Component style={styles.example} dataSet={{ media: ids.example }} />
// for older react-native-web
<Component style={styles.example} data-media={ids.example} />
Update your _document.js like example below. Further usage is exactly the same like shown above.
import Document, { Html, Head, Main, NextScript } from 'next/document';
import React from 'react';
import { flush as rnmq } from 'react-native-media-query';
import { AppRegistry } from 'react-native-web';
export default class CustomDocument extends Document {
static async getInitialProps({ renderPage }) {
AppRegistry.registerComponent('Main', () => Main);
const { getStyleElement } = AppRegistry.getApplication('Main');
const styles = [
getStyleElement(),
rnmq(),
];
return { ...renderPage(), styles: React.Children.toArray(styles) };
}
render(){
...
}
FAQs
Media queries for react-native and react-native-web
The npm package react-native-media-query receives a total of 5,370 weekly downloads. As such, react-native-media-query popularity was classified as popular.
We found that react-native-media-query 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.