
Research
/Security News
Malicious npm Packages Target WhatsApp Developers with Remote Kill Switch
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
media-hooks
Advanced tools
Use Media API with React Hooks
You can install using:
yarn add media-hooks
// or
npm install media-hooks
Media hooks provides two ways to use.
Use provider with patterns. Current support one operator (AND | OR).
App.js
import MediaProvider from 'media-hooks';
const App = () => {
const patterns = {
mobile: '(max-width: 768px)', // or { minWidth: 768 }
tablet: '(min-width: 769px) and (max-width: 1023px)', // or { minWidth: 769, operator: 'and', maxWidth: 1023 }
desktop: '(min-width: 1024px)' // or { maxWidth: 1024 }
}
return (
<MediaProvider patterns={patterns}>
<Component />
</MediaProvider>
);
}
export default App;
Component.js
import { useMedia } from 'media-hooks';
const Component = () => {
const isMobile = useMedia('mobile');
const isTablet = useMedia('tablet');
const isDesktop = useMedia('desktop');
return (
<>
{isMobile && <MobileComponent />}
{isTablet && <TabletComponent />}
{isDesktop && <DesktopComponent />}
</>
);
}
export default Component;
Use custom CSS Media Query.
Component.js
import { useCustomMedia } from 'media-hooks';
const Component = () => {
const isMobile = useCustomMedia('(max-width: 768px)');
const isTablet = useCustomMedia('(min-width: 769px) and (max-width: 1023px)');
const isDesktop = useCustomMedia('(min-width: 1024px)');
return (
<>
{isMobile && <MobileComponent />}
{isTablet && <TabletComponent />}
{isDesktop && <DesktopComponent />}
</>
);
}
export default Component;
<MediaProvider />
Prop | Description | Example |
---|---|---|
patterns | object patterns. | <MediaProvider patterns={{ mobile: '(min-width: 768px)' }}>...</MediaProvider> |
patterns | object patterns. | <MediaProvider patterns={{ mobile: { minWidth: 768 } }}>...</MediaProvider> |
useMedia()
Param | Description | Example |
---|---|---|
pattern | string pattern key in patterns. | const isMobile = useMedia('mobile') |
config | object configuration object | const isMobile = useMedia('mobile', { default: true }) |
config.default | bool fallback used when Media API is unavailable | const isMobile = useMedia('mobile', { default: true }) |
useCustomMedia()
Param | Description | Example |
---|---|---|
query | string CSS Media Query. | const isMobile = useCustomMedia('max-width: 768px') |
config | object configuration object | const isMobile = useCustomMedia('max-width: 768px', { default: true }) |
config.default | bool fallback used when Media API is unavailable | const isMobile = useCustomMedia('max-width: 768px', { default: true }) |
P.S: If Media API is unavailable and default value is not provided the hooks will return undefined
;
MIT License
Copyright (c) 2021 Matheus Pelegrinetti
FAQs
Media API using Hooks
The npm package media-hooks receives a total of 0 weekly downloads. As such, media-hooks popularity was classified as not popular.
We found that media-hooks 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.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.