Gathering detailed insights and metrics for @w11r/use-breakpoint
Gathering detailed insights and metrics for @w11r/use-breakpoint
npm install @w11r/use-breakpoint
Typescript
Module System
Node Version
NPM Version
73.8
Supply Chain
99.4
Quality
76.1
Maintenance
100
Vulnerability
100
License
TypeScript (84.26%)
SCSS (14.9%)
CSS (0.84%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
89,091
Last Day
13
Last Week
119
Last Month
272
Last Year
5,925
MIT License
17 Stars
70 Commits
3 Forks
1 Watchers
1 Branches
2 Contributors
Updated on Apr 05, 2023
Minified
Minified + Gzipped
Latest Version
2.0.0
Package Id
@w11r/use-breakpoint@2.0.0
Unpacked Size
57.43 kB
Size
12.88 kB
File Count
40
NPM Version
7.6.3
Node Version
14.4.0
Cumulative downloads
Total Downloads
No dependencies detected.
React useBreakpoint
hook to have different values for a variable
based on a breakpoints.
https://wintercounter.github.io/use-breakpoint
1npm i @w11r/use-breakpoint
Add BreakpointProvider
in your React tree.
1import { BreakpointProvider } from '@w11r/use-breakpoint' 2 3... 4 <BreakpointProvider> 5 ... 6 </BreakpointProvider> 7...
The following default breakpoints are being used, including several shorthands.
1const breakpoints = { 2 micro: [0, 375], 3 mi: [0, 375], 4 mobile: [376, 639], 5 m: [376, 639], 6 tablet: [640, 1023], 7 t: [640, 1023], 8 small: [1024, 1439], 9 s: [1024, 1439], 10 medium: [1440, 1919], 11 med: [1440, 1919], 12 large: [1920, 10000], 13 l: [1920, 10000], 14 // Multi range 15 device: [0, 1023], 16 d: [0, 1023], 17 smallDevice: [0, 639], 18 sd: [0, 639] 19}
1import { setup, breakpoints } from '@w11r/use-breakpoint' 2 3setup({ 4 breakpoints: { 5 // Extend default values 6 ...breakpoints, 7 alienDevice: [342, 43534] // from, to 8 } 9})
1useBreakpoint(defaultValue, breakpointValues) 2 3// breakpointValues: array of breakpoint based values 4[ 5 ['mobile', 300], 6 ['tablet', 400] 7] 8 9// In case you have a single breakpoint value, `['mobile', 300]` is enough instead of `[['mobile', 300]]`
In case you don't specify any value to the hook, it'll return a generated object including boolean values for each breakpoint keys that's being defined in options.
It'll return the following object with the basic setup.
{
isLandscape: false,
isPortrait: true,
isHDPI: false,
isMicro: false,
isMobile: true,
isTablet: false,
isSmall: false,
isMedium: false,
isLarge: false,
'is-Micro': false,
'is|Micro': false,
'isMicro+': true,
'is-Micro+': true,
'is|Micro+': true,
'isMicro-': false,
'is-Micro-': false,
'is|Micro-': false,
'is-Mobile': true,
'is|Mobile': true,
'isMobile+': true,
'is-Mobile+': true,
'is|Mobile+': true,
'isMobile-': true,
'is-Mobile-': true,
'is|Mobile-': true,
'is-Tablet': false,
'is|Tablet': false,
'isTablet+': false,
'is-Tablet+': false,
'is|Tablet+': false,
'isTablet-': true,
'is-Tablet-': true,
'is|Tablet-': true,
'is-Small': false,
'is|Small': false,
'isSmall+': false,
'is-Small+': false,
'is|Small+': false,
'isSmall-': true,
'is-Small-': true,
'is|Small-': true,
'is-Medium': false,
'is|Medium': false,
'isMedium+': false,
'is-Medium+': false,
'is|Medium+': false,
'isMedium-': true,
'is-Medium-': true,
'is|Medium-': true,
'is-Large': false,
'is|Large': false,
'isLarge+': false,
'is-Large+': false,
'is|Large+': false,
'isLarge-': true,
'is-Large-': true,
'is|Large-': true
}
Usage
1const { isMobile } = useBreakpoint() 2 3// The above is basically a replacement for 4const isMobile = useBreakpoint(false, ['mobile', true])
You can also access the values with suffix and prefix, but you need to rename the variables because it contains invalid character:
const { 'isMobile+': isMobile } = useBreakpoint()
Component example
1import useBreakpoint from '@w11r/use-breakpoint' 2 3const MyCmp = () => { 4 const columns = useBreakpoint([1,2], ['mobile', [2,1]]) 5 6 return <Grid cols={columns} /> 7} 8 9// Or using inline 10const MyCmp = () => { 11 return <Grid cols={useBreakpoint([1,2], ['mobile', [2,1]])} /> 12}
Rules-of-Hooks are still true in this case as well. Make sure your component will ALWAYS run it without any condition!
All breakpoint names coming with modifiers included.
-
: Landscape|
: PortraitYou can also control your value to behave as and up
and and down
.
+
: and up
-
: and down
['|mobile', 300]
: on mobile, on portrait['|mobile+', 300]
: on mobile and up, on portrait['mobile+', 300]
: on mobile and up, both portrait and landscape['mobile', 300]
: on mobile, both portrait and landscape['tablet-', 300]
: on tablet and below, both portrait and landscape['mobile-', 300]
: on mobile and down, both portrait and landscapeIt is useful when you just need simple CSS. For example with styled-components
:
1import styled from 'styled-components' 2import { mediaQuery } from '@w11r/use-breakpoint' 3 4const mediaQueryString = mediaQuery( 5 ['mobile-', `width: 100%;`] 6) 7 8const Box = styled.div` 9 ${mediaQuery( 10 ['mobile-', `width: 100%;`] 11 )} 12` 13 14// You can still use multiple queries at once just like with the hook: 15mediaQuery([['mobile-', `width: 100%`], ['medium+', `width: 50%`]])
This utility comes with additional support for shorthands
which is configurable through options
.
1setup({ 2 shorthands: { 3 foo: '@media (wow: bar) and (hmm: khm)' 4 } 5}) 6 7mediaQuery(['foo', value])
Additionally, it supports dark
and light
mode prefixes:
(
: Light mode)
: Dark mode1mediaQuery([')mobile', 'content']) 2// @media screen and (min-width: 376px) and (max-width: 639px) and (prefers-color-scheme: dark) { content } 3 4mediaQuery([')', 'content']) 5// @media screen and (prefers-color-scheme: dark) { content }
Yes! Use as fewer hooks as possible. It's always faster to have a single
isMobile
variable and have simple conditions based on it. It's even better
if you can solve your size related cases using pure CSS Media Queries.
Object
? Why the Array
structure?Object's cannot guarantee the order of the defined keys. It is crucial
to check for values in the correct order because useBreakpoint
uses
eager evaluation and mediaQuery
must maintain the defined order of
the generated Media Queries.
The hook uses eager evaluation, so the first truthy breakpoint value gets returned.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 2/29 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-03-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
550%
13
Compared to previous day
Last Week
240%
119
Compared to previous week
Last Month
19.3%
272
Compared to previous month
Last Year
-34%
5,925
Compared to previous year