Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/adenekan41/use-responsive-query

๐Ÿš€ An extremely powerful but easy to use hook for listening to media events in react.
https://github.com/adenekan41/use-responsive-query

media-queries react-hooks typescript utility

Last synced: 7 days ago
JSON representation

๐Ÿš€ An extremely powerful but easy to use hook for listening to media events in react.

Awesome Lists containing this project

README

        





use-responsive-query

An extremely powerful but easy to use hook for listening to media events in React.




[![npm](https://badge.fury.io/js/use-responsive-query.svg)](https://www.npmjs.com/package/use-responsive-query)

[![NPM](https://nodei.co/npm/use-responsive-query.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/use-responsive-query/)


### ๐Ÿ” [Try out the interactive Demo](https://codesandbox.io/s/use-responsive-query-1ep5q?file=/src/App.js) on codesandbox

## โšก๏ธAbout

[Use Responsive Query](https://github.com/adenekan41/use-responsive-query), An
extremely powerful but easy to use hook for listening to media events in React.
URQ create an experience of a javascript like **reactive accomodation** for your
react application.

## โœจ Features

- ๐Ÿš€ Typescript support
- ๐Ÿ“ฆ Light Weight ~675b (gzipped)
- ๐Ÿ”ง Cross platform supported
- ๐Ÿ™…โ€โ™‚๏ธ Zero dependencies
- โœ… Fully tested and reliable
- โš’ CommonJS, ESM & browser standalone support

## โฌ‡ Installing [use-responsive-query](https://github.com/adenekan41/use-responsive-query)

### Using NPM

```bash
npm i use-responsive-query
```

### Using Yarn

```bash
yarn add use-responsive-query
```

## ๐Ÿ›  Usage

Getting familiar with the libary and all you need is to understand how
[media queries](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries)
works, **URQ** is create with support and flexibility in mind, we have
ochestrated some set of standard screen sizes to make work easier for you.

Here are some few primary ranges you need to get aquantained with.

- `xs`: `320px` Extra small devices (portrait phones, less than 320px)
- `sm`: `320px` Extra small devices (portrait phones, less than 576px)
- `md`: `768px` Small devices (landscape phones, less than 768px)
- `lg`: `992px` Medium devices (tablets, less than 992px)
- `xl`: `1200px` Large devices (desktops, less than 1200px)

```jsx
import useResponsiveQuery from 'use-responsive-query';

export default function App() {
const isSmallDevices = useResponsiveQuery('md'); // Small devices (landscape phones, less than 768px)

return (


{isSmallDevices &&

Hello Use responsive query

}

Start hacking!!! (see changes up)



);
}
```

just like that very easy and staight forward. Easy right ?, we are also created
accomodative access for you so you can write your raw query wiht **URQ** like
this.

```jsx
import useResponsiveQuery from 'use-responsive-query';

export default function App() {
const isMin300 = useResponsiveQuery('(min-width: 300px)'); // a truthy value is called immediately our window matches this value

return (


{isMin300 &&

Hello Use responsive query

}

Start hacking!!! (see changes up)



);
}
```

Moreover, we call this pacakage the most flexible and easy to libary and we say
that with every use case and intent in mind, if you are wondering how you can
create your own custom config for your team here is how.

## ๐Ÿ”ง Creating your own config

**URQ** give you a creative option to modify your default primary media ranges
and lets you created a unique configuration access for your team.

```jsx
import useResponsiveQuery from 'use-responsive-query';

const config = {
sm: '400px',
};

export default function App() {
const isSmall = useResponsiveQuery('sm', config); // a truthy value is called immediately our window matches <400px

return (


{isSmall &&

Hello Use responsive query

}

Start hacking!!! (see changes up)



);
}
```

MIT ยฉ [codewonders.dev](https://codewonders.dev) ย ยทย  GitHub
[@adenekan41](https://github.com/adenekan41) > ย ยทย