{"id":23613688,"url":"https://github.com/freckle/react-hooks","last_synced_at":"2025-05-12T21:42:29.115Z","repository":{"id":38607114,"uuid":"479377357","full_name":"freckle/react-hooks","owner":"freckle","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-07T00:25:49.000Z","size":674,"stargazers_count":0,"open_issues_count":8,"forks_count":0,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-05-07T01:28:41.114Z","etag":null,"topics":["ghvm-managed"],"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/freckle.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-08T12:14:39.000Z","updated_at":"2025-05-07T00:24:07.000Z","dependencies_parsed_at":"2022-07-13T06:50:26.003Z","dependency_job_id":"325c7a72-73e7-4a92-8e85-a2fba2bb24f8","html_url":"https://github.com/freckle/react-hooks","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Freact-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Freact-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Freact-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Freact-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freckle","download_url":"https://codeload.github.com/freckle/react-hooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253827777,"owners_count":21970580,"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":["ghvm-managed"],"created_at":"2024-12-27T17:18:47.693Z","updated_at":"2025-05-12T21:42:29.090Z","avatar_url":"https://github.com/freckle.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @freckle/react-hooks\n\nProvides a collection of React hooks.\n\nThe key to this collection of hooks is the `useExtraDeps` hook. This hook\navoids the pitfalls of using objects and arrays as dependencies for React's\nbuilt-in `useEffect` hook. The other hooks are implemented in terms of\n`useExtraDeps`. Please see the documentation for `useExtraDeps` for further\ndetails.\n\n## Collection\n\nThis package provides (in no particular order) the following React hooks:\n\n0. `useSafeEffect` / `useSafeEffectExtraDeps`\n0. `useSafeCallback` / `useSafeCallbackExtraDeps`\n0. `usePrevious`\n0. `useExtraDeps`\n\n## Usage\n\nExample usage of an object as a dependency:\n\n```js\nimport { useSafeEffectExtraDeps } from \"@freckle/react-hooks\";\nimport { useSelector, useDispatch } from \"react-redux\";\n\nexport function StoreContainer(props: { color: Color }): React.Node {\n  const dispatch = useDispatch();\n\n  const { isLoading, itemsData, error } = useSelector(\n    (state) =\u003e state.storeReducer\n  );\n\n  useSafeEffectExtraDeps(\n    ({ color }) =\u003e {\n      dispatch(loadItems(color));\n    },\n    [dispatch],\n    {\n      color: {\n        value: props.color,\n        comparator: (color1, color2) =\u003e color1.id === color2.id,\n      },\n    }\n  );\n\n  return \u003cPiggyStore items={itemsData || []} error={error} /\u003e;\n}\n```\n\nFor simpler use cases, we can avoid the `extraDeps` bit:\n\n```js\nimport {useSafeEffect} from '@freckle/react-hooks'\nimport {useSelector, useDispatch} from 'react-redux'\n\nexport function StoreContainer(): React.Node {\n  const dispatch = useDispatch()\n\n  const {isLoading, itemsData, error} = useSelector(\n    state =\u003e state.storeReducer\n  )\n\n  useSafeEffect(() =\u003e {\n    dispatch(loadItems())\n  }, [dispatch])\n\n  return (\n    \u003cPiggyStore items={itemsData || []} error={error} /\u003e\n  )\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreckle%2Freact-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreckle%2Freact-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreckle%2Freact-hooks/lists"}