@iamkhan21/media-query-js
TypeScript icon, indicating that this package has built-in type declarations

1.4.3 • Public • Published

@iamkhan21/media-query-js

Use like css media queries in code instead ResizeObserver

npm version npm downloads

Install

npm i @iamkhan21/media-query-js

Usage

import { MediaQuery } from "@iamkhan21/media-query-js";

const query = "(max-width: 768px)";
function onChange(matches: boolean) {
  console.log(`Screen width is ${matches ? "less" : "more"} than 768px`);
}

// You will recieve match result after class initialization
const mq = new MediaQuery(query, onChange);
// For screen width more than 768px
// console.log("Screen width is more than 768px")

// Also you can subscribe and track width changes
mq.on();

// To unsubscribe call next:
mq.off();

Package Sidebar

Install

npm i @iamkhan21/media-query-js

Weekly Downloads

2

Version

1.4.3

License

MIT

Unpacked Size

7.85 kB

Total Files

6

Last publish

Collaborators

  • iamkhan21