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

1.1.2 • Public • Published

use-media-query

React hook for using media query change update on react functional components. Based on useHooks.com

Installation

npm install @pijushbarik/use-media-query --save
# or
yarn add @pijushbarik/use-media-query

Example

import React from "react";
import logo from "./logo.svg";
import "./App.css";

import useMediaQuery from "@pijushbarik/use-media-query";

function App() {
  const isScreenMdOrLess = useMediaQuery(["(max-width: 768px)"], [true], false);

  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Screen resolution is{" "}
          <b style={{ fontSize: 34 }}>
            {isScreenMdOrLess ? "less" : "greater"}
          </b>{" "}
          than 768px.
        </p>
        <p>Resize screen to see changes.</p>
      </header>
    </div>
  );
}

export default App;

Package Sidebar

Install

npm i @pijushbarik/use-media-query

Weekly Downloads

8

Version

1.1.2

License

MIT

Unpacked Size

7.51 kB

Total Files

13

Last publish

Collaborators

  • pijushbarik