{"id":19904266,"url":"https://github.com/alloc/use-element-size","last_synced_at":"2025-05-03T00:31:34.759Z","repository":{"id":38107576,"uuid":"287405629","full_name":"alloc/use-element-size","owner":"alloc","description":"Track the size of a react-dom element in 540 bytes (without ResizeObserver)","archived":true,"fork":false,"pushed_at":"2022-12-11T17:48:59.000Z","size":73,"stargazers_count":16,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T02:18:28.237Z","etag":null,"topics":["react-dom","react-hooks","reactjs"],"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/alloc.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":"2020-08-14T00:19:18.000Z","updated_at":"2024-11-11T17:01:54.000Z","dependencies_parsed_at":"2023-01-27T04:05:13.276Z","dependency_job_id":null,"html_url":"https://github.com/alloc/use-element-size","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alloc%2Fuse-element-size","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alloc%2Fuse-element-size/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alloc%2Fuse-element-size/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alloc%2Fuse-element-size/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alloc","download_url":"https://codeload.github.com/alloc/use-element-size/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252126544,"owners_count":21698963,"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":["react-dom","react-hooks","reactjs"],"created_at":"2024-11-12T20:27:37.668Z","updated_at":"2025-05-03T00:31:33.252Z","avatar_url":"https://github.com/alloc.png","language":"TypeScript","readme":"# use-element-size\n\nTrack the size of a `react-dom` element (without `ResizeObserver`).\n\nOnly **540 bytes** min+gzip!\n\n## Usage\n\n```tsx\nimport React from 'react'\nimport { useElementSize } from 'use-element-size'\n\nconst Example = () =\u003e {\n  const ref = useElementSize((size, prevSize, elem) =\u003e {\n    console.log({ size, prevSize, elem })\n  })\n  return (\n    \u003cdiv\n      ref={ref}\n      style={{\n        position: 'relative',\n        width: '50%',\n        height: '50%',\n      }}\n    /\u003e\n  )\n}\n```\n\n## Quirks\n\n- ⚠️ Be sure the tracked element **never** has `position: static`.\n\n- The `size` parameter is `null` when the tracked element is unmounted.\n\n- The `prevSize` parameter is `null` when the tracked element was just mounted.\n\n- Tracking stops when `useElementSize` is passed `false/null/undefined` instead of a function.\n\n- The callback waits until the next `requestAnimationFrame` tick before running.\n\n- The `Size` and `SizeCallback` types are exported for your convenience.\n\n## Demo\n\nhttps://codesandbox.io/s/use-element-size-demo-dszk1?file=/src/index.tsx\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falloc%2Fuse-element-size","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falloc%2Fuse-element-size","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falloc%2Fuse-element-size/lists"}