npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

match-breakpoint

v1.0.0

Published

A library of optimized React components and hooks for matching screen widths

Readme

match-breakpoint

Latest Release Total Downloads Install Size License

A library of optimized React components and hooks for matching screen widths.

Installation

yarn add match-breakpoint

// or

npm install match-breakpoint

// or

pnpm install match-breakpoint

Advantages

❇️ ⚡️ The library's components and hooks use a finite and predefined number of media match listeners, which reduces the computational load.

❇️ ✨ Using Breakpoint components allows you to avoid cumulative layout shift.

❇️ 🧩 Conditional content display is compatible with most CSS frameworks, preprocessors, etc. In particular, it's possible to use the Tailwind CSS class name preset out of the box.

❇️ 🛡️ The library supports breakpoint typing used in all components and hooks from one place.

Getting started

First of all, you need to add a breakpoints provider to your application:

import { BreakpointsProvider } from 'match-breakpoint';

const App: FC = () => (
  <BreakpointsProvider breakpoints={/* … */}>
    {/* … */}
    {/* … */}
  </BreakpointsProvider>
);

Next you need to define the breakpoints that will be used in the application:

const BREAKPOINTS = {
  md: '768px',
  lg: '1024px',
  xl: '1280px',
};

const App: FC = () => (
  <BreakpointsProvider breakpoints={BREAKPOINTS}>
    {/* … */}
    {/* … */}
  </BreakpointsProvider>
);

You can also pass a value from some configuration as breakpoints, for example from the Tailwind CSS configuration:

import tailwindConfig from '../../tailwind.config.ts';

const DEFAULT_BREAKPOINTS = {
  md: '768px',
  lg: '1024px',
  xl: '1280px',
};

const breakpoints = tailwindConfig.theme?.screens ?? DEFAULT_BREAKPOINTS;

const App: FC = () => (
  <BreakpointsProvider breakpoints={breakpoints}>
    {/* … */}
    {/* … */}
  </BreakpointsProvider>
);

After that you can use the Breakpoint component, for example:

import { Breakpoint } from 'match-breakpoint';

const Page: FC = () => (
  <>
    <Breakpoint size="md">Desktop Device Content</Breakpoint>

    <Breakpoint size="md" matchTo="max">
      Mobile Device Content
    </Breakpoint>
  </>
);

Or this using the useBreakpoint hook:

import { useBreakpoint } from 'match-breakpoint';

const Content: FC = () => {
  const isDesktop = useBreakpoint('md');

  return isDesktop ? 'Desktop Device Content' : 'Mobile Device Content';
};

Components

BreakpointsProvider

Defines breakpoint contexts. Required for the library to function.

Usage:

Example:

const BREAKPOINTS = {
  sm: 640, // Same as '640px'
  md: '768px',
  lg: {
    value: 1024, // same as '1024px'
    minClassName: 'max-lg:hidden',
    maxClassName: 'lg:hidden',
  },
  xl: {
    value: '1280px',
    minClassName: 'max-xl:hidden',
    maxClassName: 'xl:hidden',
  },
};

const App: FC = () => (
  <BreakpointsProvider breakpoints={BREAKPOINTS}>
    {/* … */}
    {/* … */}
  </BreakpointsProvider>
);

Properties:

1. breakpoints

Defines the set of breakpoints used in the application. The property is required.

Type: Record<string, string | number | BreakpointData>

Default value:

2. cssPreset

Preset of class names added to elements for conditional display. The property is optional.

Type: 'tailwind' | undefined

Default value: undefined

3. mergeClassesFunction

Function for merging class names when displaying elements conditionally. The property is optional.

Type: MergeClassesFunction | undefined

Default value: (...classes) => classes.filter(Boolean).join(' ')

4. children

Child elements. The property is required.

Type: ReactNode

Default value:

Breakpoint

Renders content based on the current screen size.

Usage:

Example:

const Page: FC = () => (
  <>
    <Breakpoint size="md">Desktop Device Content</Breakpoint>

    <Breakpoint size="md" matchTo="max">
      Mobile Device Content
    </Breakpoint>
  </>
);

Properties:

1. size

The breakpoint size specified when setting the breakpoints property in the BreakpointsProvider component. The property is required.

Type: ScreenSize

Default value:

2. matchTo

Sets which side of the breakpoint the match is made on. The property is optional.

Type: 'min' | 'max' | undefined

Default value: 'min'

3. isDefaultMatches

Default match value that determines the match until handlers are initialized. The property is optional.

Type: boolean | undefined

Default value: true

4. children

Child elements. The property is required.

Type: ReactNode

Default value:

5. as

Specifies which element the current Breakpoint should be rendered as. Once specified, props for a specified element can be passed. The property is optional.

Type: ElementType | undefined

Default value: Fragment

Hooks

useBreakpoint

Checks whether the breakpoint matches the current screen size.

Usage:

Example:

import { useBreakpoint } from 'match-breakpoint';

const Content: FC = () => {
  const isDesktop = useBreakpoint('md');

  return isDesktop ? 'Desktop Device Content' : 'Mobile Device Content';
};

Parameters

1. size

The breakpoint size specified when setting the breakpoints property in the BreakpointsProvider component. The parameter is required.

Type: ScreenSize

Default value:

2. matchTo

Sets which side of the breakpoint the match is made on. The parameter is optional.

Type: 'min' | 'max' | undefined

Default value: 'min'

3. defaultValue

Default match value that determines the match until handlers are initialized. The parameter is optional.

Type: boolean | undefined

Default value: true

Typing through an application

You can typify breakpoint names and values by extending the Breakpoints interface:

declare module 'match-breakpoint' {
  interface Breakpoints {
    sm: BreakpointData;
    md: BreakpointData;
  }
}

Then, when using the BreakpointProvider and Breakpoint components and the useBreakpoint hook, this typing will be applied to their properties and parameters:

const Content: FC = () => {
  const isDesktop = useBreakpoint('lg'); // ⛔️ TypeError: Type '"lg"' is not assignable to type '"sm" | "md"'

  // ⛔️ TypeError: Type '"lg"' is not assignable to type '"sm" | "md"'
  return <Breakpoint size="lg">{/* … */}</Breakpoint>;
};