-
Notifications
You must be signed in to change notification settings - Fork 0
hook breakpoint
Paulo Gomes da Cruz Junior edited this page Nov 19, 2025
·
1 revision
useBreakpoint is a custom React hook designed to track the current Carbon Design System breakpoint based on the browser window's width. It provides a simple and reactive way to adapt UI behavior and layout depending on screen size, enabling responsive design patterns throughout the application.
This hook listens for resize events and updates the breakpoint dynamically, returning one of the following values:
-
'max'— ≥ 1584px -
'xlg'— ≥ 1312px -
'lg'— ≥ 1056px -
'md'— ≥ 672px -
'sm'— < 672px
import useBreakpoint from '@/hooks/useBreakpoint';
const ResponsiveComponent = () => {
const breakpoint = useBreakpoint();
return (
<div>
<p>Current breakpoint: {breakpoint}</p>
{breakpoint === 'sm' && <MobileMenu />}
</div>
);
};- Initial State: The hook initializes with the current window width.
-
Event Listener: It attaches a
resizelistener to update the breakpoint on window size changes. - Cleanup: The listener is removed on component unmount to prevent memory leaks.
type BreakpointType = 'max' | 'xlg' | 'lg' | 'md' | 'sm';Carbon’s responsive grid system is breakpoint-driven, and this hook allows components to react to those breakpoints without relying on CSS media queries alone. It’s especially useful for conditional rendering, layout adjustments, and mobile-first design strategies.