@abdulghani/breakpointcontext
v1.0.7
Published
react.js breakpoint hook provided with context
Downloads
22
Readme
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
};