{"id":16427073,"url":"https://github.com/donavon/use-interval","last_synced_at":"2025-04-05T04:09:10.150Z","repository":{"id":34206790,"uuid":"170514827","full_name":"donavon/use-interval","owner":"donavon","description":"A custom React Hook that provides a declarative setInterval called useInterval.","archived":false,"fork":false,"pushed_at":"2023-01-06T16:30:36.000Z","size":2384,"stargazers_count":161,"open_issues_count":39,"forks_count":22,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T08:11:18.732Z","etag":null,"topics":["hooks","react","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/donavon.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":"2019-02-13T13:43:01.000Z","updated_at":"2024-09-05T15:39:36.000Z","dependencies_parsed_at":"2023-01-15T05:30:25.119Z","dependency_job_id":null,"html_url":"https://github.com/donavon/use-interval","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donavon%2Fuse-interval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donavon%2Fuse-interval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donavon%2Fuse-interval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donavon%2Fuse-interval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/donavon","download_url":"https://codeload.github.com/donavon/use-interval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284945,"owners_count":20913704,"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":["hooks","react","reactjs"],"created_at":"2024-10-11T08:11:27.960Z","updated_at":"2025-04-05T04:09:10.110Z","avatar_url":"https://github.com/donavon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @use-it/interval\n\nA custom React Hook that provides a declarative `setInterval` called `useInterval`.\n\n\u003e New version 1.0 has been completely rewritten in TypeScript!\n\n[![npm version](https://badge.fury.io/js/%40use-it%2Finterval.svg)](https://badge.fury.io/js/%40use-it%2Finterval)\n[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors)\n\nThis hook is an implementation of [Dan Abramov](https://github.com/gaearon)'s blog post\n[\"Making setInterval Declarative with React Hooks\"](https://overreacted.io/making-setinterval-declarative-with-react-hooks/).\n\n## Installation\n\n```bash\n$ npm i @use-it/interval\n```\n\nor\n\n```bash\n$ yarn add @use-it/interval\n```\n\n## Usage\n\nHere is a basic setup.\n\n```js\nuseInterval(callback, delay);\n```\n\n### Parameters\n\nHere are the parameters that you can use.\n\n| Parameter  | Description                                                                      |\n| :--------- | :------------------------------------------------------------------------------- |\n| `callback` | A function that will be called every `delay` milliseconds.                       |\n| `delay`    | A number representing the delay in msecs. Set to `null` to \"pause\" the interval. |\n\n### Return\n\nThis hook returns nothing.\n\n## Example\n\nLet's look at some sample code. Here is a `Counter` component that counts up every second.\n\n```js\nimport React, { useState } from 'react';\nimport useInterval from '@use-it/interval';\n\nconst Counter = ({ delay = 1000 }) =\u003e {\n  const [count, setCount] = useState(0);\n\n  useInterval(() =\u003e {\n    setCount((currentCount) =\u003e currentCount + 1);\n  }, delay);\n\n  return \u003ch1\u003e{count}\u003c/h1\u003e;\n};\n\nexport default Counter;\n```\n\n## Live demo\n\nYou can view/edit the sample code above on CodeSandbox.\n\n[![Edit demo app on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/2n542qnzr)\n\n## License\n\n**[MIT](LICENSE)** Licensed\n\n## Contributors\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://donavon.com\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/887639?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDonavon West\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/donavon/use-interval/commits?author=donavon\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#infra-donavon\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"https://github.com/donavon/use-interval/commits?author=donavon\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"#example-donavon\" title=\"Examples\"\u003e💡\u003c/a\u003e \u003ca href=\"#maintenance-donavon\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"https://github.com/donavon/use-interval/pulls?q=is%3Apr+reviewed-by%3Adonavon\" title=\"Reviewed Pull Requests\"\u003e👀\u003c/a\u003e \u003ca href=\"#tool-donavon\" title=\"Tools\"\u003e🔧\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://twitter.com/dan_abramov\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/810438?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDan Abramov\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/donavon/use-interval/commits?author=gaearon\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#blog-gaearon\" title=\"Blogposts\"\u003e📝\u003c/a\u003e \u003ca href=\"#ideas-gaearon\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"#tutorial-gaearon\" title=\"Tutorials\"\u003e✅\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://michaelsync.net\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/192911?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMichael Sync\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/donavon/use-interval/issues?q=author%3Amichaelsync\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://onetwo.ren\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/3746270?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003elin onetwo\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/donavon/use-interval/commits?author=linonetwo\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/donavon/use-interval/issues?q=author%3Alinonetwo\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://daniel-lauzon.com/\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/326183?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDaniel Lauzon\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/donavon/use-interval/commits?author=daneroo\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonavon%2Fuse-interval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdonavon%2Fuse-interval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonavon%2Fuse-interval/lists"}