{"id":19153387,"url":"https://github.com/leetcode-opensource/react-resize-context","last_synced_at":"2025-08-23T03:18:21.040Z","repository":{"id":44593574,"uuid":"142691972","full_name":"LeetCode-OpenSource/react-resize-context","owner":"LeetCode-OpenSource","description":"⚡️A high performance React component for responding to resize event","archived":false,"fork":false,"pushed_at":"2023-04-07T09:53:19.000Z","size":352,"stargazers_count":22,"open_issues_count":15,"forks_count":3,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-04-19T19:05:33.326Z","etag":null,"topics":["leetcode","react","react-context","resize","resize-events","resize-observer"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-resize-context","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/LeetCode-OpenSource.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-28T16:18:30.000Z","updated_at":"2023-12-07T08:06:07.000Z","dependencies_parsed_at":"2024-06-18T20:12:58.890Z","dependency_job_id":"5a3c4dfe-3e75-47c6-a4cc-11fcd45bfc2b","html_url":"https://github.com/LeetCode-OpenSource/react-resize-context","commit_stats":{"total_commits":126,"total_committers":3,"mean_commits":42.0,"dds":"0.23809523809523814","last_synced_commit":"21f41459cf618b4e1fedfd1ea7c871c23dea1544"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeetCode-OpenSource%2Freact-resize-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeetCode-OpenSource%2Freact-resize-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeetCode-OpenSource%2Freact-resize-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeetCode-OpenSource%2Freact-resize-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LeetCode-OpenSource","download_url":"https://codeload.github.com/LeetCode-OpenSource/react-resize-context/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252826059,"owners_count":21810042,"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":["leetcode","react","react-context","resize","resize-events","resize-observer"],"created_at":"2024-11-09T08:22:56.406Z","updated_at":"2025-05-07T06:26:36.211Z","avatar_url":"https://github.com/LeetCode-OpenSource.png","language":"TypeScript","readme":"# react-resize-context\n\n[![npm version](https://badge.fury.io/js/react-resize-context.svg)](https://www.npmjs.com/package/react-resize-context)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/LeetCode-OpenSource/react-resize-context/pulls)\n[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)\n\nA high performance React component for responding to resize event.\n\n### Install\n```bash\nnpm install react-resize-context\n```\n\n## Examples\n* [A simple example](https://codesandbox.io/embed/jjjmp4z6yy)\n* [Multiple components listen resize event from the same parent element](https://codesandbox.io/embed/vnz20v4j65)\n\n## APIs\nProvides a `{ ResizeProvider, ResizeConsumer }` pair which just like React's [Context API](https://reactjs.org/docs/context.html). When renders a context `ResizeConsumer`, it will listen to the resize event from the [children](https://reactjs.org/docs/jsx-in-depth.html#children-in-jsx) of closest matching `ResizeProvider` above it in the tree.\n\n### \\\u003cResizeProvider \\/\\\u003e\n\u003e A React component that allows `ResizeConsumer` to listen to the resize event from `ResizeProvider`'s children element.\n\n### \\\u003cResizeConsumer \\/\\\u003e\n\u003e It is also a React component that triggers two callback functions when the element is resized. One is `onSizeChanged` and the other is `updateDatasetBySize`.\n```typescript\ninterface Size {\n  width: number;\n  height: number;\n}\n\ninterface DOMStringMap {\n    [name: string]: string | undefined;\n}\n\ntype onSizeChanged =  (size: Size) =\u003e void;\ntype updateDatasetBySize = (size: Size) =\u003e DOMStringMap;\n```\n\n#### About `updateDatasetBySize`\nThe return value of `updateDatasetBySize` is updated to the [dataset](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset) of the current ResizeConsumer's DOM element, so we can easily update the styles of different sizes through the CSS attribute selectors (eg: `[data-size=\"small\"]`).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleetcode-opensource%2Freact-resize-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleetcode-opensource%2Freact-resize-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleetcode-opensource%2Freact-resize-context/lists"}