# react-use-breakpoint

> Use breakpoints in JS when dealing with React based applications

Latest version **1.4.1** (published 2025-06-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-use-breakpoint
pnpm add react-use-breakpoint
yarn add react-use-breakpoint
bun add react-use-breakpoint
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.4.1 |
| Published | 2025-06-21 |
| First published | 2022-12-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 21 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Joel Pierre |
| Maintainers | joelpierre |
| Keywords | breakpoint, matchMedia, react, responsive, typescript, viewport, window.matchMedia |

## Links

- npm: https://www.npmjs.com/package/react-use-breakpoint
- Repository: https://github.com/joelpierre/use-breakpoint
- Issues: https://github.com/joelpierre/use-breakpoint/issues
- npm.io page: https://npm.io/package/react-use-breakpoint

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.4.1 (latest) — 2025-06-21
- 1.4.0 — 2025-06-21
- 1.3.0 — 2025-06-20
- 1.2.1 — 2023-03-19
- 1.2.0 — 2023-03-18
- 1.1.4 — 2022-12-17
- 1.1.3 — 2022-12-17
- 1.1.2 — 2022-12-17
- 1.1.1 — 2022-12-17
- 1.1.0 — 2022-12-17
- 1.0.9 — 2022-12-17
- 1.0.8 — 2022-12-17
- 1.0.6 — 2022-12-16
- 1.0.5 — 2022-12-16

## README

# react-use-breakpoint

## Rational

A React hook to get the current breakpoint via the MatchMedia API. Tiny, fast, and easy to use. I created this as I
found myself copying this bad boy around every project I did... so I figured I'd make it a package. Other plugins out
there are not exactly what I needed, and although I think getting breakpoints in JS should be a **last resort**. There
is undoubtedly a time and place for it. Especially as designers design more creative layouts that are not easily
achievable with CSS alone.

## Getting Started

Install the package

```shell
npm install react-use-breakpoint
yarn add react-use-breakpoint
```

Wrap your apps root component with the `BreakpointProvider` component. This will provide the `useBreakpoint` hook to all
child components.

```tsx
import {BreakpointProvider} from 'react-use-breakpoint';

const App = () => (
    <BreakpointProvider>
        <MyComponent/>
    </BreakpointProvider>
);
```

The default breakpoint size values are:

| Breakpoint | Size (px) |
|------------|-----------|
| xs         | 360       |
| sm         | 640       |
| md         | 960       |
| lg         | 1280      |
| xl         | 1440      |

You can customise these values `xs, sm, md, lg, xl` to fit your needs like so (strings or numbers are accepted):

```tsx
import {BreakpointProvider} from 'react-use-breakpoint';

const App = () => (
    <BreakpointProvider
        breakpointOverrides={{
            xs: 360,
            sm: '400'
        }}
    >
        <MyComponent/>
    </BreakpointProvider>
);
```

## Hook Usage

Within all child components you can then leverage the `useBreakpoint()` hook to get the current breakpoints.

Specifying no arguments will return an object with min and max breakpoints `{ min: {...}, max: {...} }`. The function
overload handles the types for you 😉.

```tsx
import {useBreakpoint} from 'react-use-breakpoint';

const MyComponent = () => {
    const {min} = useBreakpoint();
    const {isXs} = min;

    return <div>Current breakpoint: {breakpoint}</div>;
};
```

If you specify a breakpoint "direction" (min or max) you will get an object back with all the breakpoint sizes and their
assigned `boolean` value.

```tsx
import {useBreakpoint} from 'react-use-breakpoint';

const MyComponent = () => {
    const {isXs, isSm, isMd} = useBreakpoint('min');
    // isXs = true
    // isSm = false
    // isMd = false
...
    return <div>Current breakpoint: {breakpoint}</div>;
};
```

## Feature Requests...

Sure... open up an issue, and I'll see what I can do.

## Todo

- [ ] Add tests for the hook

---
_Source: https://npm.io/package/react-use-breakpoint · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
