{"id":18510768,"url":"https://github.com/envato/react-breakpoints","last_synced_at":"2025-04-09T04:33:22.951Z","repository":{"id":54177397,"uuid":"223337145","full_name":"envato/react-breakpoints","owner":"envato","description":"Respond to changes in a DOM element's size. With React Breakpoints, element queries are no longer \"web design's unicorn\" 🦄","archived":false,"fork":false,"pushed_at":"2025-03-20T03:15:28.000Z","size":320,"stargazers_count":71,"open_issues_count":1,"forks_count":2,"subscribers_count":33,"default_branch":"main","last_synced_at":"2025-03-23T23:27:18.986Z","etag":null,"topics":["breakpoints","element-queries","hooks","media-queries","performance","react","react-hooks","resize-observer"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/envato.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null}},"created_at":"2019-11-22T06:19:31.000Z","updated_at":"2024-09-18T11:06:20.000Z","dependencies_parsed_at":"2022-08-13T08:21:02.717Z","dependency_job_id":null,"html_url":"https://github.com/envato/react-breakpoints","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Freact-breakpoints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Freact-breakpoints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Freact-breakpoints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Freact-breakpoints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/envato","download_url":"https://codeload.github.com/envato/react-breakpoints/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980833,"owners_count":21027803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["breakpoints","element-queries","hooks","media-queries","performance","react","react-hooks","resize-observer"],"created_at":"2024-11-06T15:24:58.464Z","updated_at":"2025-04-09T04:33:22.440Z","avatar_url":"https://github.com/envato.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"200\" src=\"./React-Breakpoints.png\" alt=\"React Breakpoints logo\" /\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003eReact Breakpoints\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"npm version\" src=\"https://img.shields.io/npm/v/@envato/react-breakpoints?style=for-the-badge\" /\u003e\n  \u003cimg alt=\"react version\" src=\"https://img.shields.io/npm/dependency-version/@envato/react-breakpoints/peer/react?style=for-the-badge\"\u003e\n  \u003cimg alt=\"license\" src=\"https://img.shields.io/npm/l/@envato/react-breakpoints?style=for-the-badge\" /\u003e\n  \u003ca href=\"CODE-OF-CONDUCT.md\"\u003e\u003cimg alt=\"contributor covenant v2.0 adopted\" src=\"https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=for-the-badge\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n`react-breakpoints` allows you to respond to changes in a DOM element's size. You can change the evaluated logic and rendered output of components based on observed size changes in DOM elements. For example, you can change a dropdown menu to a horizontal list menu based on its parent container's width without using CSS media queries.\n\n# 📦 What's in the box?\n\n\u003e No polling. No event listening. No sentinel elements. **Just a [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)!**\n\nThis package provides you with:\n\n- a [`\u003cProvider\u003e`](/docs/api.md#provider) to instantiate the `ResizeObserver`;\n- an [`\u003cObserve\u003e`](/docs/api.md#observe) component to observe changes in a DOM element and respond to them.\n\nFor power users this package also provides:\n\n- a [`useBreakpoints()`](/docs/api.md#usebreakpoints) hook to change a component's behaviour based on the observed size information in the nearest parent `\u003cObserve\u003e`;\n- a [`useResizeObserver()`](/docs/api.md#useresizeobserver) hook to connect a DOM element in your component to the instantiated `ResizeObserver` on `\u003cProvider\u003e`;\n- a [`useResizeObserverEntry()`](/docs/api.md#useresizeobserverentry) hook to retrieve the `ResizeObserverEntry` put on the nearest `\u003cContext\u003e`. This is what `useBreakpoints()` uses under the hood.\n\n# 🐉 Be careful using this package when\u0026hellip;\n\n- \u0026hellip;all you want is the low-level API stuff. See [@envato/react-resize-observer-hook](https://github.com/envato/react-resize-observer-hook).\n- \u0026hellip;you want _real_ CSS Element Queries. At the end of the day, this is still a JS solution.\n- \u0026hellip;you care deeply about [Cumulative Layout Shift](https://web.dev/cls/) on public pages. **Keep reading though, this package may still be of value to you!**\n\n# 🏅 This package is _really good_ at\u0026hellip;\n\n- \u0026hellip;following the latest [draft spec](https://drafts.csswg.org/resize-observer/), giving you access to cutting edge features like `devicePixelContentBoxSize` and [per-fragment](https://drafts.csswg.org/css-break-3/) observation.\n- \u0026hellip;performantly observing many elements with a single `ResizeObserver` instance. None of that \"a new `ResizeObserver` instance per observed element\" bloat that [some](https://github.com/ZeeCoder/use-resize-observer/blob/314b29c33cfcd2c51b8854b775b0a2a5c325d94a/src/index.ts#L151-L157) alternative packages implement.\n- \u0026hellip;building highly-responsive private dashboards 📊. One key thing this package (and every other `ResizeObserver` package out there) can contribute negatively to is [Cumulative Layout Shifting](https://web.dev/cls/). At Envato we've had great success using this package on pages that are only visible after signing in, like our Author Dashboard. We've had less success using it in places where search engines can go, on components with responsive styles that changed the layout vertically. One of our company values is \"Tell It Like It Is\", so we're letting you know to **be mindful of when and how you use `ResizeObserver` for responsive layouts.**\n\n# ⚡️ Quick start\n\nFollow these **minimum required steps** to get started with `react-breakpoints`. This is just the tip of the iceberg, though. Check the [API Docs](/docs/api.md) for all options.\n\n```shell\nnpm install @envato/react-breakpoints\n```\n\n## Wrap your component tree with the provider\n\n```jsx\nimport { Provider as ResizeObserverProvider } from '@envato/react-breakpoints';\n\nconst App = () =\u003e \u003cResizeObserverProvider\u003e...\u003c/ResizeObserverProvider\u003e;\n```\n\n⚠️ **Caution** — You may need to pass some props to `\u003cProvider\u003e` to increase browser support. Please refer to the [API Docs](/docs/api.md#provider).\n\n## Observe an element and use the results\n\n```jsx\nimport { Observe } from '@envato/react-breakpoints';\n\nconst exampleBreakpoints = {\n    widths: {\n      0: 'mobile',\n      769: 'tablet',\n      1025: 'desktop'\n    }\n  };\n\nexport const ExampleComponent = () =\u003e (\n  \u003cObserve breakpoints={exampleBreakpoints}\u003e\n    {({ observedElementProps, widthMatch = 'ssr' }) =\u003e (\n      \u003cdiv {...observedElementProps}\u003e\n        \u003cdiv className={widthMatch}\u003e\n      \u003c/div\u003e\n    )}\n  \u003c/Observe\u003e\n);\n```\n\nSee the [API Docs](/docs/api.md) for reference guides and usage examples.\n\n# Observing vs. Consuming `ResizeObserverSize`\n\nThere is an important distinction between the `boxSize` you observe and the `boxSize` you pass to your breakpoints. See [Observing vs. Consuming `ResizeObserverSize`](/docs/boxSizes.md) for more information.\n\n# Re-rendering\n\nUsing [`useResizeObserver()`](/docs/api.md#useresizeobserver), [`useResizeObserverEntry()`](/docs/api.md#useresizeobserverentry) or [`useBreakpoints()`](/docs/api.md#usebreakpoints) in your components causes them to re-render **every time a resize is observed**.\n\n# Server-Side Rendering\n\nSee [Server-Side Rendering](/docs/server-side-rendering.md) for more information.\n\n# Maintainers\n\n- [Marc Dingena](https://github.com/mdingena) (owner)\n\n# Contributing\n\nFor bug fixes, documentation changes, and small features:\n\n1. Fork this repository.\n1. Create your feature branch (git checkout -b my-new-feature).\n1. Commit your changes (git commit -am 'Add some feature').\n1. Push to the branch (git push origin my-new-feature).\n1. Create a new Pull Request.\n\n**For larger new features**: Do everything as above, but first also make contact with the project maintainers to be sure your change fits with the project direction and you won't be wasting effort going in the wrong direction.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvato%2Freact-breakpoints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenvato%2Freact-breakpoints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvato%2Freact-breakpoints/lists"}