0.1.7 • Published 4 years ago

@regrapes/react-breakpoint-hooks v0.1.7

Weekly downloads
-
License
-
Repository
-
Last release
4 years ago

@regrapes/react-breakpoint-hooks

install size

This project is maintained by REGRAPES.

Intention

Creates easy to use breakpoint hooks for react, based on @react-hook/media-query package and inspired by Material UIs breakpoint definitions (can be overwritten).

Install

npm i @regrapes/react-breakpoint-hooks

Example

import { BreakpointProvider } from "@regrapes/react-breakpoint-hooks";

<BreakpointProvider>
  <App />
</BreakpointProvider>;
import { useBreakpoints } from "@regrapes/react-breakpoint-hooks";

function App() {
  const { isScreenMD } = useBreakpoints();

  return (
    <div className="App">
      {isScreenMD.exact && <div>Renders only on exact screen size MD</div>}
      {isScreenMD.up && (
        <div>Renders only on screen size MD and above (LG, XL)</div>
      )}
      {isScreenMD.down && (
        <div>Renders only on screen size MD and below (SM, XS)</div>
      )}
    </div>
  );
}

Default breakpoints

BreakpointSize (px)
XS0
SM600
MD960
LG1280
XL1920

Inspired by Material UIs breakpoints

Options

useBreakpoints() provides...

const { isScreenXS, isScreenSM, isScreenMD, isScreenLG, isScreenXL } = useBreakpoints();

Every options provide exact, up and down property, which return a boolean.

Overwriting breakpoints

You can use your own breakpoints by passing your own breakpoints into the BreakpointProvider:

import { BreakpointProvider } from "@regrapes/react-breakpoint-hooks";

const BREAKPOINTS = {
  XS: 0,
  SM: 600,
  MD: 960,
  LG: 1280,
  XL: 1920,
};

<BreakpointProvider breakpoints={BREAKPOINTS}>
  <App />
</BreakpointProvider>;

LICENSE

MIT

0.1.7

4 years ago

0.1.4

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago