
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
react-tw-breakpoints
Advanced tools
useBreakpoint hooks and tw-based components
Optimized SSR-friendly React hooks to get the current breakpoint based on:
matchMedia and is global to window.ResizeObserver to measure an element and return its breakpoint.Includes condition helpers (largerThan/lessThan/onlyAt) and is tree-shakeable.
npm install react-tw-breakpoints
Peer deps: React 18/19 (DOM).
Tailwind is NOT required for the hooks. If you use the experimental UI components (Container, Grid), Tailwind CSS is required and you must configure a safelist so their dynamic classes are included. See docs/guides/tailwind-safelist.md.
The library uses Tailwind-aligned breakpoints: xs (0px), sm (640px), md (768px), lg (1024px), xl (1280px), _2xl (1536px), and more.
Note:
_2xl, _3xl) because TypeScript identifiers cannot start with digits. See BreakpointEnum.2xl). See Grid.Scopes:
_5xl. See BREAKPOINT_ORDER._7xl. See CONTAINER_BREAKPOINT_ORDER.import { useBreakpoint, useBreakpointCondition } from 'react-tw-breakpoints';
function Example() {
const bp = useBreakpoint(); // 'xs' | 'sm' | ...
const isLgUp = useBreakpointCondition({ largerThan: 'lg' });
const onlyMd = useBreakpointCondition({ onlyAt: 'md' });
return (
<div>
<p>Viewport BP: {bp}</p>
{isLgUp && <span>≥ lg</span>}
{onlyMd && <span>md only</span>}
</div>
);
}
import { useRef } from 'react';
import { useContainerBreakpoint } from 'react-tw-breakpoints';
function Card() {
const ref = useRef<HTMLDivElement>(null);
const bp = useContainerBreakpoint(ref); // based on the element width
return (
<div ref={ref} style={{ width: '100%' }}>
{bp === 'xs' && <OneCol />}
{bp === 'md' && <TwoCols />}
{bp === 'lg' && <ThreeCols />}
</div>
);
}
useBreakpoint() - Returns the active viewport breakpoint label.
useBreakpointCondition(opts) - Evaluates viewport conditions (largerThan, lessThan, onlyAt).
useBreakpointContainer() - Container breakpoint set (viewport-based).
useContainerBreakpoint(ref) - True per-element breakpoint using ResizeObserver.
Helper Hooks: useBreakpointUp, useBreakpointDown, useBreakpointOnly, useBreakpointBetween
getCurrentBreakpoint() - Synchronously get current breakpoint (SSR-safe).
getMediaQuery(query) - Get cached MediaQueryList for custom queries.
[!CAUTION] These components are experimental and may change their API or functionality. They are subject to discussion and improvement proposals, so breaking changes or even removal may occur. Use them at your own risk.
There are some basic layout components to use in your application. These are independent of the hooks in this library, so they are not affected by changes to the API for hooks, helpers, etc.
Many UI libraries don't have basic layout components. You probably need something simple and straightforward like a <Container>, and you may not want to have to define it in every project you work on if you use the same UI library or another one that doesn't have one.
Container - Centered wrapper with max-width constraints.
Grid - 12-column responsive grid system.
import { useBreakpointCondition } from 'react-tw-breakpoints';
function Navigation() {
const isMobile = useBreakpointCondition({ lessThan: 'lg' });
return <nav>{isMobile ? <MobileMenu /> : <DesktopMenu />}</nav>;
}
import { useRef } from 'react';
import { useContainerBreakpoint } from 'react-tw-breakpoints';
function Card() {
const cardRef = useRef<HTMLDivElement>(null);
const breakpoint = useContainerBreakpoint(cardRef);
return (
<div ref={cardRef}>
{breakpoint === 'xs' && <CompactLayout />}
{breakpoint === 'lg' && <ExpandedLayout />}
</div>
);
}
For style-based container queries without JavaScript, use native CSS @container. Learn more.
Hooks use useSyncExternalStore for safe subscriptions. In SSR they return base values (xs or false) and hydrate on the client. No duplicate listeners in StrictMode.
matchMedia: All modern browsersResizeObserver: Chrome/Edge 64+, Safari 13.1+, Firefox 69+@container: Chrome/Edge 105+, Safari 16+, Firefox 110+Why two kinds of “container breakpoints”?
useBreakpointContainer uses viewport with a different label set (useful if you want two global grids).useContainerBreakpoint is true per element.Can I change breakpoints?
src/const/breakpoints.ts and rebuild the package.Tree‑shaking?
package.json exports ESM with sideEffects: false. Import only what you use.Please read the contribution guidelines first.
FAQs
useBreakpoint hooks and tw-based components.
The npm package react-tw-breakpoints receives a total of 125 weekly downloads. As such, react-tw-breakpoints popularity was classified as not popular.
We found that react-tw-breakpoints demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.