{"id":20672730,"url":"https://github.com/nas5w/use-effect-debounced","last_synced_at":"2025-06-30T16:38:46.553Z","repository":{"id":66175498,"uuid":"179891918","full_name":"nas5w/use-effect-debounced","owner":"nas5w","description":"A custom React hook that provides a debounced version of useEffect.","archived":false,"fork":false,"pushed_at":"2019-04-06T22:18:39.000Z","size":157,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T20:44:58.007Z","etag":null,"topics":["javascript","react","react-hooks","reactjs","useeffect"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nas5w.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-04-06T22:08:32.000Z","updated_at":"2024-03-05T11:52:52.000Z","dependencies_parsed_at":"2023-02-21T06:01:17.826Z","dependency_job_id":null,"html_url":"https://github.com/nas5w/use-effect-debounced","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nas5w/use-effect-debounced","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nas5w%2Fuse-effect-debounced","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nas5w%2Fuse-effect-debounced/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nas5w%2Fuse-effect-debounced/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nas5w%2Fuse-effect-debounced/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nas5w","download_url":"https://codeload.github.com/nas5w/use-effect-debounced/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nas5w%2Fuse-effect-debounced/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262811433,"owners_count":23368111,"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":["javascript","react","react-hooks","reactjs","useeffect"],"created_at":"2024-11-16T20:38:38.357Z","updated_at":"2025-06-30T16:38:46.533Z","avatar_url":"https://github.com/nas5w.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# useEffectDebounced\n\nThis repository demonstrates creating a custom hook called `useEffectDebounced`. It works just like `useEffect` except the function you pass to `useEffectDebounced` only be executed after a user-specified amount of time (and only if the the parameters on which the effect depends do not change).\n\n## Implementation\n\nthe `useEffectDebounced` hook is implemented as follows:\n\n```javascript\nimport { useEffect } from \"react\";\n\nconst useEffectDebounced = (func, values, time) =\u003e {\n  useEffect(() =\u003e {\n    let db = setTimeout(() =\u003e {\n      func();\n    }, time);\n\n    return () =\u003e clearTimeout(db);\n  }, values);\n};\n\nexport default useEffectDebounced;\n```\n\nThe passed function `func` is executed in a `setTimeout` after the user specified `time`. However, if one of the `values` the hook depends on is changed, the clean-up function `() =\u003e clearTimeout(db)` is executed, meaning `func` will not execute.\n\n## Example Usage\n\nThis application includes an example usage in which a textbox is used to filter through a list of countries. The filtering is done in the `useEffectDebounced` hook, meaning the filtering will not occur until the specified period of time has passed without additional changes to the textbox.\n\n```javascript\nimport React, { useState } from \"react\";\nimport useEffectDebounced from \"./useEffectDebounced\";\nimport countries from \"./countries\";\n\nconst App = () =\u003e {\n  const [filteredCountries, setFilteredCountries] = useState(countries);\n  const [search, setSearch] = useState(\"\");\n\n  useEffectDebounced(\n    () =\u003e {\n      const filtered = countries.filter(country =\u003e\n        country.name.toLowerCase().includes(search.toLowerCase())\n      );\n      setFilteredCountries(filtered);\n    },\n    [search],\n    1000\n  );\n\n  return (\n    \u003cdiv\u003e\n      \u003cinput value={search} onChange={e =\u003e setSearch(e.target.value)} /\u003e\n      \u003cul\u003e\n        {filteredCountries \u0026\u0026\n          filteredCountries.map((country, index) =\u003e {\n            return \u003cli key={index}\u003e{country.name}\u003c/li\u003e;\n          })}\n      \u003c/ul\u003e\n    \u003c/div\u003e\n  );\n};\n\nexport default App;\n```\n\n![Countries being filtered with debounce](https://i.imgur.com/sEOFZH8.gif)\n\n## Feedback\n\nI would appreciate any feedback you have on this custom hook!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnas5w%2Fuse-effect-debounced","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnas5w%2Fuse-effect-debounced","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnas5w%2Fuse-effect-debounced/lists"}