Responsive Media Query Component
Better manage alternate layouts (like desktop/tablet/mobile) with no explicit connection between the media query details and the alternate views.
Example from Capital One's React web app.
The first component is MediaQuery. This lets you set any media queries allows you to set the media query. By default it uses just a desktop and mobile setting. When the screen resizes, the children components will render the corresponding view for that layout.
The second component, Responsive, allow you to switch between completely different views with no explicit data passed down.
Example
var App = React; var MiddleMan = React var ResponsiveChildComponent = React; ReactDOM;
How is works
The parent component, MediaQuery, adds a listener to window resize only once for the entire app. On mount and resize request it will check the media queries and update them only if there is a change. All the children that use the Responsive component will be trigger whenever it changes.
Advanced use
The MediaQuery component has a query prop that can be whatever media query you would like to trigger.
var App = React; var ResponsiveChildComponent = React; ReactDOM;
What not to do
This is only v1. Don't mix and match multiple MediaQuery components. Just one in the app so other will pick it up. More features will be added as needed/requested.