{"id":18285402,"url":"https://github.com/lh0x00/rc-target-size","last_synced_at":"2025-04-05T07:32:17.229Z","repository":{"id":65482693,"uuid":"137567992","full_name":"lh0x00/rc-target-size","owner":"lh0x00","description":"a tool help get size and offset of element for React, support higher-order component and component render.","archived":false,"fork":false,"pushed_at":"2020-07-13T22:06:24.000Z","size":71,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T12:58:26.011Z","etag":null,"topics":["dom","element","height","polyfill","props","react","resize","size","style","target","width"],"latest_commit_sha":null,"homepage":"https://codesandbox.io/s/1yrwq9wm54","language":"JavaScript","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/lh0x00.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}},"created_at":"2018-06-16T09:08:33.000Z","updated_at":"2019-03-22T04:20:31.000Z","dependencies_parsed_at":"2023-01-25T10:45:32.402Z","dependency_job_id":null,"html_url":"https://github.com/lh0x00/rc-target-size","commit_stats":null,"previous_names":["lamhieu-vk/rc-target-size"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lh0x00%2Frc-target-size","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lh0x00%2Frc-target-size/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lh0x00%2Frc-target-size/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lh0x00%2Frc-target-size/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lh0x00","download_url":"https://codeload.github.com/lh0x00/rc-target-size/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305879,"owners_count":20917201,"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":["dom","element","height","polyfill","props","react","resize","size","style","target","width"],"created_at":"2024-11-05T13:16:34.801Z","updated_at":"2025-04-05T07:32:12.215Z","avatar_url":"https://github.com/lh0x00.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\n[![npm version][npm-version-image]][npm-url]\n[![npm downloads][npm-downloads-image]][npm-url]\n[![github issues][github-issues-image]][github-issues-url]\n[![build status][travis-image]][travis-url]\n\nA tool help get size of element for React, support higher-order component and component render.\nYou can get the size of the element using a row without changing any of the elements!\n\n## Reference\n\n### rc-pure-component\n\nA wrapper use pure component wrap stateless functional components to class use pure component to reduce re-render. [read more](https://www.npmjs.com/package/rc-pure-component)\n\n### resize-observer-polyfill\n\nA polyfill for the resize observer api. [read more](https://www.npmjs.com/package/resize-observer-polyfill)\n\n# Installation\n\n```bash\n# use npm\n$ npm install rc-target-size\n\n# or yarn\n$ yarn add rc-target-size\n```\n\n## CDN\n\n```html\n// unpkg\n\u003cscript src=\"https://unpkg.com/rc-target-size/dist/rc-target-size.js\"\u003e\u003c/script\u003e\n\n// jsdelivr\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/rc-target-size/dist/rc-target-size.js\"\u003e\u003c/script\u003e\n```\n\n**Note** use CDN in browser, you can call `rcTargetSize` from Window API. it is available at `window.rcTargetSize`\n\n# Usage\n\n## Component render\n\n[read more](https://github.com/lamhieu-vk/rc-target-size/blob/master/examples/component.js)\n\n```javascript\nimport React from \"react\";\nimport { TargetSize } from \"rc-target-size\";\n\nconst ResizeOfMe = ({ width, height }) =\u003e (\n  \u003cdiv\u003e\n    component - size of me: {width}x{height}\n  \u003c/div\u003e\n);\n\nconst onSize = data =\u003e console.log(\"onSize\", data);\n\nconst App = () =\u003e (\n  \u003cdiv\u003e\n    // simple\n    \u003cTargetSize\u003e\n      \u003cResizeOfMe /\u003e\n    \u003c/TargetSize\u003e\n    // or use with config\n    \u003cTargetSize mode=\"debounce\" rate={1000} handleHeight onSize={onSize}\u003e\n      \u003cResizeOfMe /\u003e\n    \u003c/TargetSize\u003e\n  \u003c/div\u003e\n);\n\nexport default App;\n```\n\n## HOC render\n\n[read more](https://github.com/lamhieu-vk/rc-target-size/blob/master/examples/hoc.js)\n\n```javascript\nimport React from \"react\";\nimport { targetSize } from \"rc-target-size\";\n\nconst ResizeOfMeWrapped = ({ width, height }) =\u003e (\n  \u003cdiv\u003e\n    hoc - size of me: {width}x{height}\n  \u003c/div\u003e\n);\n\n// simple\nconst ResizeOfMe = targetSize()(ResizeOfMeWrapped);\n\n// or use with config\nconst ResizeOfMe = targetSize({\n  mode: \"debounce\",\n  rate: 1000,\n  handleWidth: true,\n  onSize: data =\u003e console.log(\"onSize\", data),\n})(ResizeOfMeWrapped);\n\nconst App = () =\u003e (\n  \u003cdiv\u003e\n    \u003cResizeOfMe /\u003e\n  \u003c/div\u003e\n);\n\nexport default App;\n```\n\n## Child function\n\n[read more](https://github.com/lamhieu-vk/rc-target-size/blob/master/examples/childFunction.js)\n\n```javascript\nimport React from \"react\";\nimport { TargetSize } from \"rc-target-size\";\n\nconst onSize = data =\u003e console.log(\"onSize\", data);\n\nconst App = () =\u003e (\n  \u003cdiv\u003e\n    // simple\n    \u003cTargetSize\u003e\n      {({ width, height }) =\u003e (\n        \u003cdiv\u003e\n          child function - size of me: {width}x{height}\n        \u003c/div\u003e\n      )}\n    \u003c/TargetSize\u003e\n    // or use with config\n    \u003cTargetSize mode=\"debounce\" rate={1000} handleHeight onSize={onSize}\u003e\n      {({ width, height }) =\u003e (\n        \u003cdiv\u003e\n          child function - size of me: {width}x{height}\n        \u003c/div\u003e\n      )}\n    \u003c/TargetSize\u003e\n  \u003c/div\u003e\n);\n\nexport default App;\n```\n\n# Documents\n\n## Config\n\n| name           | type    | description                                                                                                            |\n| -------------- | ------- | ---------------------------------------------------------------------------------------------------------------------- |\n| mode           | String  | (optional) values is 'debounce' or 'throttle', mode refresh size of component when resize. default: 'throttle'         |\n| rate           | Number  | (optional) rate refresh size of component when resize, measurement is milliseconds. default: 500                       |\n| querySelector  | String  | (optional) if you do not want to get the size of the current element, you can take another element. default: undefined |\n| handleWidth    | Boolean | (optional) only update value when width resized. default: false                                                        |\n| handleHeight   | Boolean | (optional) only update value when height resized. default: false                                                       |\n| handleOffset   | Boolean | (optional) only update value when offset changed. default: false                                                       |\n| updateOnChange | Boolean | (optional) will received values since the initial creation? default: true                                              |\n| onSize         | Func    | (optional) function callback on have size. default: undefined                                                          |\n\n## Props\n\nvalues return to your components, append to props\n\n| name      | type    | description                                |\n| --------- | ------- | ------------------------------------------ |\n| width     | Number  | width of element. default: 0               |\n| height    | Number  | height of element. default: 0              |\n| offset    | Object  | offset of element. default: { x: 0, y: 0 } |\n| canUseDOM | Boolean | the test was able to use DOM or not        |\n\n[npm-url]: https://npmjs.org/package/rc-target-size\n[npm-version-image]: https://badge.fury.io/js/rc-target-size.svg\n[npm-downloads-image]: https://img.shields.io/npm/dm/rc-target-size.svg\n[github-issues-image]: https://img.shields.io/github/issues/lamhieu-vk/rc-target-size.svg\n[github-issues-url]: https://github.com/lamhieu-vk/rc-target-size/issues\n[travis-image]: https://travis-ci.com/lamhieu-vk/rc-target-size.svg?branch=master\n[travis-url]: https://travis-ci.com/lamhieu-vk/rc-target-size?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flh0x00%2Frc-target-size","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flh0x00%2Frc-target-size","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flh0x00%2Frc-target-size/lists"}