1.0.7 • Published 4 years ago

@abdulghani/breakpointcontext v1.0.7

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

Breakpointcontext

a react.js hook for breakpoint that's provided with context for efficient checking

Install

get it from yarn/npm whatever

yarn add @abdulghani/breakpointcontext

npm install @abdulghani/breakpointcontext

Usage

use it as simple as

import BreakpointContext, { useBreakpoint } from "@abdulghani/breakpointcontext";

const MyComponent = () => {
  return (
    <BreakpointContext>
      <YourSuperAwesomeChildren>
    </BreakpointContext>
  )
}

// and use it in your component
const YourSuperAwesomeChildren = () => {
  const breakpoint = useBreakpoint();

  if (breakpoint === "sm")
    return <div>it's small</div>
  else
    return <div>it's huge</div>
}

you can put your own config to define your own set of breakpoints

const MyComponent = () => {
  return (
     <BreakpointContext breakpoints={myBreakpoints}>
      <YourSuperAwesomeChildren>
    </BreakpointContext>
  )
}

the option is typed as such

type breakpoints = {
  [keys: string]: number; // set of breakpoint value tied to the key as the label
};
1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago