Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@herbco/react-media-match
Advanced tools
Mobile first react responsive framework made easy.
SSR
for any device.npm install react-media-match
yarn add react-media-match
Just:
Each Media Query is responsible only for a single "dimension" - width, height or orientation.
"Pick value to the left" is the core concept. It protects you from mistakes, and allows to skip intermediate resolutions, if they should inherit styles from "lesser" query.
react-media-match was made with maintainability and mobile first approach in mind. It makes things simpler.
react-media-match provides two components and one function, and none of them awaits query as a prop,
import { MediaMatcher, ProvideMediaMatchers } from "react-media-match";
<ProvideMediaMatchers> // this component will calculate all Media's and put data into the React Context
<MediaMatcher
mobile={"render for mobile"}
// tablet={"tablet"} // mobile will be rendered for "skipped" tablet
desktop={"render desktop"}
/>
<MediaMatcher
mobile={"render for mobile"}
tablet={null} // nothing will be rendered for tablet, as long you clearly defined it
desktop={"render desktop"}
/>
<MediaMatches> // will provide matches information via render-props
{matches => (
<span> testing {
// pick matching values
pickMatch(matches, {
mobile: "mobile",
// tablet: "tablet", // the same rules are applied here
desktop: "desktop",
})
}</span>
)}
</MediaMatches>
<MediaMatches> // will provide matches information via render-props
{(_,pickMatch) => ( // you can get pickMatch from MediaMatches
<span> testing {
// pick matching values
pickMatch({
mobile: "mobile",
// tablet: "tablet", // the same rules are applied here
desktop: "desktop",
})
}</span>
)}
</MediaMatches>
</ProvideMediaMatchers>
PS: Don’t forget to wrap all this with ProvideMediaMatchers - without it MediaMatches will always picks the "last" branch.
There is no way to support MediaQuery on the Server Side, so the only way to generate the expected result is to mock a predicted device.
We are providing a special component which will mock data only on server size, and compare predicted media on componentMount on client size.
It also has a special prop hydrated
which will lead to forced react tree remount
in case prediction was wrong, and rendered tree will not match hydrated one.
(use only in case of ReactDOM.hydrated
)
import { MediaMatcher, MediaServerRender } from "react-media-match";
<MediaServerRender predicted="desktop" hydrated>
<MediaMatcher
mobile={"render for mobile"}
// tablet={"tablet"} // mobile will be rendered for "skipped" tablet
desktop={"render desktop"}
/>
</MediaServerRender>
If prediction has failed - it will inform you, and might help to mitigate rendering issues.
You may use ua-parser-js, to detect device type, and pick desired screen resolution, or use react-ugent to make it a bit more declarative.
react-media-match provides an API for "default" queries, and a factory method to create custom media queries.
createMediaMatcher(breakPoints: { key: string })
- factory for a new API for provided breakpoints.
The object with following props will be returned:
There is also pre-exported API for default breakpoints - mobile, tablet, desktop
pickMatch(matches, matchers)
- function, return value from matchers matching matches.
ProvideMediaMatchers
- component, calculates media queries and stores them in context.
MediaMatches
- component, returns current matchers as a render prop
MediaMatcher
- component, renders path for active match
MediaServerRender
- component, helps render server-size
import { createMediaMatcher } from "react-media-match";
const Orientation = createMediaMatcher({
portrait: "(orientation: portrait)",
landscape: "(orientation: landscape)"
});
<Orientation.Match
portrait="One"
landscape="Second"
/>
import { MediaMock, ProvideMediaMatchers } from "react-media-match";
// override all data
<ProvideMediaMatchers state={{mobile:true, tablet:false, desktop:false}}>
....
</ProvideMediaMatchers>
<MediaMock mobile>
....
</MediaMock>
<Orientation.Mock portrait>
....
</Orientation.Mock>
https://codesandbox.io/s/o7q3zlo0n9
Just provide state
for ProvideMediaMatchers, and it will control all the nested matchers. Could be used to provide not media-based rules.
ProvideMediaMatchers
has a state
parameter, and you might specify it override any information, and control all the nested matchers.MediaMock
will completely mock media settings.Both mocks are not working for Inline
component.
Testing and mocking are related to SSR rendering, and you may use MediaServerRender for tests and Mocks for SSR as well.
MIT
FAQs
React made responsible
We found that @herbco/react-media-match demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.