{"id":25289028,"url":"https://github.com/bettertyped/react-performance-hooks","last_synced_at":"2025-10-27T22:30:58.307Z","repository":{"id":61494117,"uuid":"519340997","full_name":"BetterTyped/react-performance-hooks","owner":"BetterTyped","description":"🎊 React hooks that will make you extremely easy to debounce and throttle your functions to gain instant performance boost!","archived":false,"fork":false,"pushed_at":"2024-10-18T17:32:43.000Z","size":296,"stargazers_count":22,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T12:25:00.921Z","etag":null,"topics":["debounce","hooks","performance","react","throttle","usedebounce","usedebouncestate","usethrottle","usethrottlestate"],"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/BetterTyped.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"Code_of_Conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2022-07-29T20:24:43.000Z","updated_at":"2024-10-18T17:28:58.000Z","dependencies_parsed_at":"2023-01-31T08:46:12.083Z","dependency_job_id":null,"html_url":"https://github.com/BetterTyped/react-performance-hooks","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/BetterTyped%2Freact-performance-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetterTyped%2Freact-performance-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetterTyped%2Freact-performance-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BetterTyped%2Freact-performance-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BetterTyped","download_url":"https://codeload.github.com/BetterTyped/react-performance-hooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238566097,"owners_count":19493414,"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":["debounce","hooks","performance","react","throttle","usedebounce","usedebouncestate","usethrottle","usethrottlestate"],"created_at":"2025-02-12T23:27:51.468Z","updated_at":"2025-10-27T22:30:52.945Z","avatar_url":"https://github.com/BetterTyped.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🎊 React Performance Hooks\n\n\u003cp\u003e\n  \u003ca href=\"https://bettertyped.com/\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/static/v1?label=\u0026message=BetterTyped\u0026color=333\u0026logo=BT\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/BetterTyped/react-performance-hooks\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/github/stars/BetterTyped/react-performance-hooks?logo=star\u0026color=118ab2\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/BetterTyped/react-performance-hooks/blob/main/License.md\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/github/license/BetterTyped/react-performance-hooks?logo=law\u0026color=yellow\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/semantic-release/semantic-release\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/badge/semver-commitzen-e10079?logo=semantic-release\u0026color=e76f51\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/BetterTyped/react-performance-hooks\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript\u0026logoColor=white\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@better-hooks/performance\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/npm/v/@better-hooks/performance.svg?logo=npm\u0026color=E10098\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@better-hooks/performance\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/bundlephobia/minzip/@better-hooks/performance?color=blueviolet\u0026logo=package\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@better-hooks/performance\"\u003e\n    \u003cimg src=\"https://custom-icon-badges.demolab.com/npm/dm/@better-hooks/performance?logoColor=fff\u0026logo=trending-up\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## About\n\nDebounce and throttle your functions, state and effects to gain performance boost!\n\n## Key Features\n\n🔮 **Simple usage**\n\n🚀 **Fast and light**\n\n✨ **Debounce and Throttle**\n\n🎊 **Lifecycle debounce and throttle**\n\n📡 **State debounce and throttle**\n\n## Installation\n\n```bash\nnpm install --save @better-hooks/performance\n```\n\nor\n\n```bash\nyarn add @better-hooks/performance\n```\n\n---\n\n## Examples\n\n#### useDeepEffect\n\nThis hook deeply compares the dependencies optimizing rerendering effects\n\n```tsx\nimport React from \"react\";\nimport { useDebounce } from \"@better-hooks/performance\";\n\nconst MyComponent: React.FC = () =\u003e {\n  const {debounce, reset, active} = useDeepEffect(() =\u003e {\n    // do something\n  }, [{a: 123}]) // \u003c--- we will check if the deps are equal between rerenders\n\n  return (\n    // ...\n  )\n}\n\n```\n\n---\n\n#### useDebounce\n\nThis hook allows debouncing of the given function. Function will be called after some amount of time\nfrom the last execution. We can adjust debounce time with additional props.\n\n```tsx\nimport React from \"react\";\nimport { useDebounce } from \"@better-hooks/performance\";\n\nconst MyComponent: React.FC = () =\u003e {\n  const {debounce, reset, active} = useDebounce({ delay: 600 })\n\n  // Standard usage\n  const onTyping = () =\u003e {\n    debounce(() =\u003e {\n      // debounced logic\n    })\n  }\n\n  // Dynamic delay value\n  const onTypingDynamic = (value: string, customDelay: number) =\u003e {\n    debounce(() =\u003e {\n      // debounced logic\n    }, { delay: customDelay })\n  }\n\n  return (\n    // ...\n  )\n}\n\n```\n\n---\n\n#### useDebounceState\n\nThis hook allows debouncing of state. Value will be saved after some amount of time from the last\nexecution of set function. We can adjust debounce time with additional props.\n\n```tsx\nimport React from \"react\";\nimport { useWindowEvent } from \"@better-hooks/window\";\nimport { useDebounceState } from \"@better-hooks/performance\";\n\nconst MyComponent: React.FC = () =\u003e {\n  const [value, setValue] = useDebounceState(\"20px\")\n\n  useWindowEvent(\"scroll\", (e) =\u003e {\n    setValue(e.scrollY + \"px\");\n  })\n\n  return (\n    // ...\n  )\n}\n\n```\n\n---\n\n#### useDebounceEffect\n\nThis hook allows debouncing of lifecycle effect.\n\n```tsx\nimport React from \"react\";\nimport { useDebounceEffect } from \"@better-hooks/performance\";\n\nconst MyComponent: React.FC = (props) =\u003e {\n\n  useDebounceEffect(() =\u003e {\n    // Do something\n  }, { delay: 200 }, [props])\n\n  return (\n    // ...\n  )\n}\n\n```\n\n---\n\n#### useThrottle\n\nThis hook allows debouncing of the given function.\n\n```tsx\nimport React from \"react\";\nimport { useThrottle } from \"@better-hooks/performance\";\n\nconst MyComponent: React.FC = ({ delay }) =\u003e {\n  const {throttle, reset, active} = useThrottle(delay)\n\n  // Standard usage\n  const onScroll = () =\u003e {\n    throttle(() =\u003e {\n      // throttle logic\n    })\n  }\n\n  // Dynamic delay value\n  const onScrollDynamic = (value: string, customDelay: number) =\u003e {\n    throttle(() =\u003e {\n      // throttle logic\n    }, customDelay)\n  }\n\n  return (\n    // ...\n  )\n}\n\n```\n\n---\n\n#### useThrottleState\n\nThis hook allows throttling of state. We can adjust execution interval time and execution timeout\ntime with additional props.\n\n```tsx\nimport React from \"react\";\nimport { useWindowEvent } from \"@better-hooks/window\";\nimport { useThrottleState } from \"@better-hooks/performance\";\n\nconst MyComponent: React.FC = () =\u003e {\n  const [value, setValue] =  useThrottleState(\"20px\")\n\n  useWindowEvent(\"scroll\", (e) =\u003e {\n    setValue(e.scrollY + \"px\");\n  })\n\n  return (\n    // ...\n  )\n}\n\n```\n\n```tsx\nimport React from \"react\";\nimport { useWindowEvent } from \"@better-hooks/window\";\nimport { useThrottleState } from \"@better-hooks/performance\";\n\nconst MyComponent: React.FC = () =\u003e {\n  const [value, setValue] =  useThrottleState(\"20px\", {\n    interval: 200, // We will save values at least once per 200ms\n    timeout: 400 // Last set state action will get triggered after 400ms, we can also disable it\n  })\n\n  useWindowEvent(\"scroll\", (e) =\u003e {\n    setValue(e.scrollY + \"px\");\n  })\n\n  return (\n    // ...\n  )\n}\n\n```\n\n---\n\n#### useThrottleEffect\n\nThis hook allows debouncing of lifecycle effect.\n\n```tsx\nimport React from \"react\";\nimport { useThrottleEffect } from \"@better-hooks/performance\";\n\nconst MyComponent: React.FC = (props) =\u003e {\n\n   useThrottleEffect(() =\u003e {\n    // Do something\n  }, { interval: 200, timeout: false }, [props])\n\n  return (\n    // ...\n  )\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbettertyped%2Freact-performance-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbettertyped%2Freact-performance-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbettertyped%2Freact-performance-hooks/lists"}