{"id":41096303,"url":"https://github.com/liamross/use-data","last_synced_at":"2026-01-22T14:58:08.284Z","repository":{"id":57141934,"uuid":"184680719","full_name":"liamross/use-data","owner":"liamross","description":"A React hook for async fetching of data, data manipulation, and take latest vs take every functionality.","archived":false,"fork":false,"pushed_at":"2020-09-04T20:50:17.000Z","size":474,"stargazers_count":2,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-09T19:14:36.851Z","etag":null,"topics":["async","data","hook","hooks","react"],"latest_commit_sha":null,"homepage":null,"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/liamross.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-05-03T01:06:26.000Z","updated_at":"2022-07-15T21:21:06.000Z","dependencies_parsed_at":"2022-09-26T16:50:38.028Z","dependency_job_id":null,"html_url":"https://github.com/liamross/use-data","commit_stats":null,"previous_names":["liamross/use-data-hook"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/liamross/use-data","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liamross%2Fuse-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liamross%2Fuse-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liamross%2Fuse-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liamross%2Fuse-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liamross","download_url":"https://codeload.github.com/liamross/use-data/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liamross%2Fuse-data/sbom","scorecard":{"id":587516,"data":{"date":"2025-08-11","repo":{"name":"github.com/liamross/use-data","commit":"86ddcd0f7253d4b513a7e7c3c60e3b698936ee64"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 1/23 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 8 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"57 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-6chw-6frg-f759","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9","Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f","Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p","Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv","Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8","Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65","Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh","Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44","Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp","Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T20:56:51.430Z","repository_id":57141934,"created_at":"2025-08-20T20:56:51.430Z","updated_at":"2025-08-20T20:56:51.430Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28664810,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T14:01:31.714Z","status":"ssl_error","status_checked_at":"2026-01-22T13:59:23.143Z","response_time":144,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["async","data","hook","hooks","react"],"created_at":"2026-01-22T14:58:08.205Z","updated_at":"2026-01-22T14:58:08.276Z","avatar_url":"https://github.com/liamross.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Use Data [![Build Status](https://travis-ci.org/liamross/use-data.svg?branch=master)](https://travis-ci.org/liamross/use-data) [![NPM Version](https://badge.fury.io/js/use-data.svg)](https://www.npmjs.com/package/use-data)\n\n1. Fetches data from an async function\n1. Allows you to manipulate the data à la Redux\n1. Will throw out outdated API calls by default\n\nBasic usage:\n\n```tsx\nimport React, {FC} from 'react';\nimport useData from 'use-data';\nimport {someApi} from './someApi';\n\nconst FunctionalComponent: FC\u003c{someProp: string}\u003e = ({someProp}) =\u003e {\n  const {loading, error, data} = useData(() =\u003e someApi(someProp));\n\n  if (error) return \u003cp\u003eError...\u003c/p\u003e;\n  if (!data || loading) return \u003cp\u003eLoading...\u003c/p\u003e;\n  return \u003cp\u003e{data.someString}\u003c/p\u003e;\n};\n```\n\n\u003cdetails\u003e\u003csummary\u003eExpand for more advanced usage:\u003c/summary\u003e\n\n```tsx\nimport React, {FC, useEffect} from 'react';\nimport useData from 'use-data';\nimport {getUser} from './getUserAPI';\n\nconst FunctionalComponent: FC\u003c{userId: string}\u003e = ({userId}) =\u003e {\n  const {loading, error, data, fireFetch, setData} = useData(\n    () =\u003e getUser(userId),\n    {username: '', age: 0},\n    {fireOnMount: false, takeEvery: true},\n  );\n\n  useEffect(() =\u003e {\n    // Wait for userId to fetch (see fireOnMount is false).\n    if (userId) fireFetch();\n  }, [fireFetch, userId]);\n\n  const handleSetUsername = () =\u003e {\n    // Uses the function option for newData in order to only change username.\n    setData(oldUser =\u003e ({...oldUser!, username: 'John Doe'}));\n  };\n\n  if (error) return \u003cp\u003eError...\u003c/p\u003e;\n  if (!data || loading) return \u003cp\u003eLoading...\u003c/p\u003e;\n  return (\n    \u003c\u003e\n      \u003cp\u003e{data.username}\u003c/p\u003e\n      \u003cbutton onClick={handleSetUsername}\u003e\n        {\"Set username to 'John Doe'\"}\n      \u003c/button\u003e\n    \u003c/\u003e\n  );\n};\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eExpand for setting up hook with Context:\u003c/summary\u003e\n\n```tsx\nimport React, {createContext, FC} from 'react';\nimport useData, {StatusObject} from 'use-data';\nimport {getName} from './getNameAPI';\n\ninterface ContextData {\n  firstName: string;\n  lastName: string;\n}\n\nexport const NameContext = createContext\u003cStatusObject\u003cContextData\u003e\u003e({\n  loading: false,\n  error: new Error('No Provider'),\n  data: null,\n  fireFetch: () =\u003e new Error('No Provider'),\n  setData: () =\u003e new Error('No Provider'),\n});\n\nexport const NameProvider: FC = ({children}) =\u003e {\n  const statusObject = useData(getName);\n\n  return (\n    \u003cNameContext.Provider value={statusObject}\u003e{children}\u003c/NameContext.Provider\u003e\n  );\n};\n```\n\n\u003c/details\u003e\n\n## API\n\nThe `useData` hook is the only non-type export. The type definition is as\nfollows:\n\n```ts\ndeclare function useData\u003cD\u003e(\n  asyncFetch: () =\u003e Promise\u003cD\u003e,\n  initialData?: D,\n  options?: UseDataOptions,\n): StatusObject\u003cD\u003e;\n```\n\nIf you are using this in a TypeScript project, you do not need to provide a type\nfor the generic `D`, as it will be automatically parsed from the return type of\n`asyncFetch`. However in some cases it may be desirable to define it (see more\ninformation in the `initialData` section).\n\nIt accepts three arguments:\n\n#### `asyncFetch` - _`() =\u003e Promise\u003cD\u003e`_\n\nAny async fetch function that you want to use to fetch data from. The type will\nbe automatically parsed from the return type.\n\nExample usage:\n\n```ts\n// If your function takes no arguments, you can pass it in directly:\nconst {loading, error, data} = useData(asyncFetch);\n\n// If it requires arguments, wrap it in an arrow function:\nconst {loading, error, data} = useData(() =\u003e asyncFetch(someValue));\n```\n\n#### `initialData` - _`D`_\n\nInitial data must match the return type of `asyncFetch`, or the generic `D`. For\nexample, the following will result in an error:\n\n```ts\nconst {loading, error, data} = useData(\n  async () =\u003e {\n    return {a: {b: 'b contents'}};\n  },\n  {a: null},\n);\n```\n\nThis is because it expects `initialData` to be of type `{ a: { b: string; }; }`.\nTo fix this, you will need to define the generic:\n\n```ts\nconst {loading, error, data} = useData\u003c{a: null | {b: string}}\u003e(\n  async () =\u003e {\n    return {a: {b: 'b contents'}};\n  },\n  {a: null},\n);\n```\n\nThis will allow the property `a` to be either null or `{ b: string; }`.\n\n#### `options` - _`UseDataOptions`_\n\nOptions is an optional object that has the following structure:\n\n```ts\nexport interface UseDataOptions {\n  fireOnMount?: boolean;\n  takeEvery?: boolean;\n}\n```\n\n1. `fireOnMount` - Default: _true_. Should the hook fire the `asyncFetch` on\n   mount.\n1. `takeEvery` - Default: _false_. Should the hook take every call rather than\n   throwing out active calls when new ones are made.\n\n#### `@returns` - _`StatusObject\u003cD\u003e`_\n\nThe hook returns an object with 5 properties:\n\n1. `loading` - True if currently fetching.\n1. `error` - The error object if your fetch fails, or null if not failed.\n1. `data` - The data from your async fetch, or null if not fetched.\n1. `fireFetch` - Fire the async function that was provided to useData. You may\n   pass it an async function to call instead of `asyncFetch`,\n1. `setData` - Mutate the data. Either a function that takes old data and\n   returns the new data, or data of type `D`. Calling this will turn `error` to\n   null. Additionally takes a parameter to stop loading when called (loading\n   will continue by default).\n\n```ts\ninterface UseDataState\u003cD\u003e {\n  loading: boolean;\n  error: Error | null;\n  data: D | null;\n}\n\ninterface StatusObject\u003cD\u003e extends UseDataState\u003cD\u003e {\n  fireFetch: (newAsyncFetch?: () =\u003e Promise\u003cD\u003e) =\u003e void;\n  setData: (\n    newData: D | ((oldData: D | null) =\u003e D),\n    stopLoading?: boolean,\n  ) =\u003e void;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliamross%2Fuse-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliamross%2Fuse-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliamross%2Fuse-data/lists"}