Gathering detailed insights and metrics for use-breakpoint
Gathering detailed insights and metrics for use-breakpoint
Gathering detailed insights and metrics for use-breakpoint
Gathering detailed insights and metrics for use-breakpoint
@yamada-ui/use-breakpoint
Yamada UI useBreakpoint custom hook
use-breakpoint-value
`npm install --save use-breakpoint-value`
@kodingdotninja/use-tailwind-breakpoint
Custom hooks to use breakpoints for React 🎐🔨
@w11r/use-breakpoint
React useBreakpoint hook to have different values for a variable based on a breakpoints.
A React hook for getting the current responsive media breakpoint
npm install use-breakpoint
Typescript
Module System
Node Version
NPM Version
92.4
Supply Chain
86.9
Quality
79.2
Maintenance
100
Vulnerability
100
License
TypeScript (86.83%)
JavaScript (11.66%)
Shell (1.51%)
Total Downloads
3,295,387
Last Day
584
Last Week
28,712
Last Month
119,944
Last Year
1,323,198
MIT License
86 Stars
207 Commits
7 Forks
2 Watchers
1 Branches
3 Contributors
Updated on Jun 01, 2025
Minified
Minified + Gzipped
Latest Version
4.0.6
Package Id
use-breakpoint@4.0.6
Unpacked Size
26.30 kB
Size
5.69 kB
File Count
23
NPM Version
10.9.2
Node Version
22.13.1
Published on
Feb 02, 2025
Cumulative downloads
Total Downloads
Last Day
-12.7%
584
Compared to previous day
Last Week
0.9%
28,712
Compared to previous week
Last Month
11.6%
119,944
Compared to previous month
Last Year
76.4%
1,323,198
Compared to previous year
32
A React hook (>=18) for getting the current responsive media breakpoint.
useBreakpoint
Initialize useBreakpoint
with a configuration object, and optionally a default breakpoint name (in non-window environments like SSR). The return value will be an object with the breakpoint's name (string
), min-width, and max-width values (number
):
1import useBreakpoint from 'use-breakpoint' 2 3/** 4 * It is important to bind the object of breakpoints to a variable for memoization to work correctly. 5 * If they are created dynamically, try using the `useMemo` hook. 6 */ 7const BREAKPOINTS = { mobile: 0, tablet: 768, desktop: 1280 } 8 9const CurrentBreakpoint = () => { 10 const { breakpoint, maxWidth, minWidth } = useBreakpoint( 11 BREAKPOINTS, 12 'desktop', 13 ) 14 return <p>The current breakpoint is {breakpoint}!</p> 15}
Given a configuration BREAKPOINTS = { mobile: 0, tablet: 768, desktop: 1280 }
and a window size of 1280x960
, the hook will return as the breakpoint:
const { breakpoint } = useBreakpoint(BREAKPOINTS)
undefined
when rendered server-side'desktop'
when rendered client-sideconst { breakpoint } = useBreakpoint(BREAKPOINTS, 'mobile')
'mobile'
when rendered server-side'mobile'
on the first client-side render'desktop'
on subsequent client-side rendersIf supplied a default breakpoint, the hook will always return that value when rendered server-side. To not cause inconsistencies during the first client-side render, the default value is also used client-side for the first render, instead of the (possibly different) real breakpoint.
For example, given a breakpoint config:
1const { breakpoint } = useBreakpoint(BREAKPOINTS, 'mobile')
When rendered server-side, breakpoint === 'mobile'
always, because there is no window. On client-side with a desktop
-sized window, on the first render breakpoint === 'mobile'
, and then on following renders breakpoint === 'desktop'
. This is to ensure ReactDOM.hydrate
behaves correctly. The implementation relies on the useSyncExternalStore
React hook with the getServerSnapshot
callback.
This hook uses the window.matchMedia functionality to calculate the current breakpoint. For a list of breakpoints, we generate some css media queries in the form of (min-width: XXXpx) and (max-width: YYYpx)
and then add listeners for the changes. useBreakpoint
will then update its return value when the breakpoint changes from one rule to another.
getCSSMediaQueries
To use the same breakpoint configuration in CSS-in-JS, you can use the getCSSMediaQueries
helper:
1import { getCSSMediaQueries } from 'use-breakpoint' 2 3const BREAKPOINTS = { mobile: -1, tablet: 768, desktop: 1280 } 4 5const cssQueries = getCSSMediaQueries(BREAKPOINTS, 'screen') 6// { 7// desktop: "@media only screen and (min-width: 1280px)", 8// mobile: "@media only screen and (max-width: 767px)", 9// tablet: "@media only screen and (min-width: 768px) and (max-width: 1279px)", 10// }
The second option can be omitted to leave out the media type condition.
This project is built with Typescript. A Storybook is included for local previewing. The easiest way to get started is cloning the repo and starting the storybook server locally via npm start
.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
Found 2/23 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
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
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
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 More