{"id":28281544,"url":"https://github.com/phantomstudios/use-animation-frame","last_synced_at":"2026-02-27T14:34:24.961Z","repository":{"id":42534731,"uuid":"359265820","full_name":"phantomstudios/use-animation-frame","owner":"phantomstudios","description":"A React hook to effortlessly run a single shared requestAnimationFrame() for all instances of the hook used with adjustable frames per second.","archived":false,"fork":false,"pushed_at":"2025-11-17T17:00:23.000Z","size":1215,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-17T17:32:39.570Z","etag":null,"topics":["hook","hooks","react","react-hook","useanimationframe"],"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/phantomstudios.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-04-18T22:28:29.000Z","updated_at":"2025-11-17T17:20:40.000Z","dependencies_parsed_at":"2025-07-02T18:21:21.287Z","dependency_job_id":"a98b6daa-f331-4c01-913a-e922907c9b73","html_url":"https://github.com/phantomstudios/use-animation-frame","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/phantomstudios/use-animation-frame","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantomstudios%2Fuse-animation-frame","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantomstudios%2Fuse-animation-frame/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantomstudios%2Fuse-animation-frame/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantomstudios%2Fuse-animation-frame/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phantomstudios","download_url":"https://codeload.github.com/phantomstudios/use-animation-frame/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantomstudios%2Fuse-animation-frame/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29899919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T14:30:36.354Z","status":"ssl_error","status_checked_at":"2026-02-27T14:30:01.989Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["hook","hooks","react","react-hook","useanimationframe"],"created_at":"2025-05-21T12:13:13.362Z","updated_at":"2026-02-27T14:34:24.955Z","avatar_url":"https://github.com/phantomstudios.png","language":"TypeScript","readme":"# use-animation-frame\n\n[![NPM version][npm-image]][npm-url]\n[![Actions Status][ci-image]][ci-url]\n[![PR Welcome][npm-downloads-image]][npm-downloads-url]\n\nA React hook to effortlessly run a single shared [requestAnimationFrame()](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) for all instances of the hook used with adjustable FPS (frames per second).\n\n## Installation\n\nInstall this package with `npm`.\n\n```bash\nnpm i @phntms/use-animation-frame\n```\n\n## API\n\nAccepts first `callback` and second `framesPerSecond`:\n\n```ts\nuseAnimationFrame(callback, framesPerSecond);\n```\n\n`callback` is **required** and is called on _every_ animation frame window.\n\n`framesPerSecond` is _optional_ and can be used to control how often callback triggers. By default callback will trigger around ~60 times per second (approximately every ~16ms), though you can change this, for example, `30` can be used to trigger callback ~30 times per second.\n\n**Note**: Any FPS can be used, although intervals cannot be faster than the `requestAnimationFrame()` limit.\n\n### Output\n\nThe callback returns `deltaTime` - the total time in `ms` since the hook last run.\n\n**Note**: Due to the nature of `requestAnimationFrame()` this will always likely differ in time.\n\n## Single Shared `requestAnimationFrame()` Instance\n\nMost implementations of this hook create unique `requestAnimationFrame()` loops for all instances of the hook. This is fine when you only use the hook once, but if you start running multiple hooks simultaneously this can get expensive. To counteract this issue, this library only ever creates a single global loop that we 'hook' into for all instances of the hook used. As such, you haven't got to worry about the potential performance hit of using multiple instances of the hook. Additionally if used alongside custom `framesPerSecond`, you can get much greater performance out of your components!\n\n## Examples\n\n```ts\nimport useAnimationFrame from \"@phntms/use-animation-frame\";\n\nuseAnimationFrame((deltaTime: number) =\u003e {\n  console.log(\n    `I'm called approximately every ~16ms, but I was actually triggered after ${deltaTime}ms.`,\n  );\n});\n\nuseAnimationFrame((deltaTime: number) =\u003e {\n  console.log(\n    `I'm called approximately 30 times per second, but I was actually trigger after ${deltaTime}ms.`,\n  );\n}, 30);\n```\n\n## 🍰 Contributing\n\nWant to get involved, or found an issue? Please contribute using the GitHub Flow. Create a branch, add commits, and open a Pull Request or submit a new issue.\n\nPlease read `CONTRIBUTING` for details on our `CODE_OF_CONDUCT`, and the process for submitting pull requests to us!\n\n[npm-image]: https://img.shields.io/npm/v/@phntms/use-animation-frame.svg?style=flat-square\u0026logo=react\n[npm-url]: https://npmjs.org/package/@phntms/use-animation-frame\n[npm-downloads-image]: https://img.shields.io/npm/dm/@phntms/use-animation-frame.svg\n[npm-downloads-url]: https://npmcharts.com/compare/@phntms/use-animation-frame?minimal=true\n[ci-image]: https://github.com/phantomstudios/use-animation-frame/workflows/Test/badge.svg\n[ci-url]: https://github.com/phantomstudios/use-animation-frame/actions\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphantomstudios%2Fuse-animation-frame","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphantomstudios%2Fuse-animation-frame","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphantomstudios%2Fuse-animation-frame/lists"}