{"id":40801996,"url":"https://github.com/kqito/use-tus","last_synced_at":"2026-01-21T20:45:08.370Z","repository":{"id":38384782,"uuid":"353994979","full_name":"kqito/use-tus","owner":"kqito","description":"React hooks for resumable file uploads using tus","archived":false,"fork":false,"pushed_at":"2025-08-20T12:49:59.000Z","size":2587,"stargazers_count":117,"open_issues_count":2,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-23T18:09:31.602Z","etag":null,"topics":["hooks","react","react-hooks","tus","tus-js-client"],"latest_commit_sha":null,"homepage":"https://kqito.github.io/use-tus/?path=/story/usetus--basic","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/kqito.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-02T11:10:47.000Z","updated_at":"2025-09-09T12:28:09.000Z","dependencies_parsed_at":"2022-08-09T03:16:12.914Z","dependency_job_id":"fa75309a-e068-464b-bb64-6e7eb9f56403","html_url":"https://github.com/kqito/use-tus","commit_stats":{"total_commits":115,"total_committers":3,"mean_commits":"38.333333333333336","dds":"0.017391304347826098","last_synced_commit":"e9c0d3cbd1e4871541c4ff35116d0928eb94e772"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"purl":"pkg:github/kqito/use-tus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kqito%2Fuse-tus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kqito%2Fuse-tus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kqito%2Fuse-tus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kqito%2Fuse-tus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kqito","download_url":"https://codeload.github.com/kqito/use-tus/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kqito%2Fuse-tus/sbom","scorecard":{"id":569119,"data":{"date":"2025-08-11","repo":{"name":"github.com/kqito/use-tus","commit":"4e74fd0348dd05ed809f425068cb66f23649d3bc"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"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":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","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":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/npm-publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/npm-publish.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/npm-publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:53: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/npm-publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:54: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/npm-publish.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:59: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/npm-publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/npm-publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/npm-publish.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/npm-publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/test.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/test.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/kqito/use-tus/test.yml/main?enable=pin","Info:   0 out of   8 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   4 third-party GitHubAction dependencies pinned"],"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":"Code-Review","score":0,"reason":"Found 1/12 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":"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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/npm-publish.yml:1","Warn: no topLevel permission defined: .github/workflows/test.yml:1","Info: no jobLevel write permissions found"],"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":"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":"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":"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":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"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 26 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":"42 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-prr3-c3m5-p7q2","Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6","Warn: Project is vulnerable to: GHSA-67mh-4wv8-2f99","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8mmm-9v2q-x3f9","Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22","Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp","Warn: Project is vulnerable to: GHSA-76c9-3jph-rj3q","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w","Warn: Project is vulnerable to: GHSA-566m-qj78-rww5","Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-w5hq-hm5m-4548","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-pq67-2wwv-3xjx","Warn: Project is vulnerable to: GHSA-8cj5-5rvv-wf4v","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-92r3-m2mg-pj97","Warn: Project is vulnerable to: GHSA-c24v-8rfc-w8vw","Warn: Project is vulnerable to: GHSA-8jhw-289h-jh2g","Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3","Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx","Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6","Warn: Project is vulnerable to: GHSA-x574-m823-4x7w","Warn: Project is vulnerable to: GHSA-4r4m-qw57-chr8","Warn: Project is vulnerable to: GHSA-xcj6-pq6g-qj4x","Warn: Project is vulnerable to: GHSA-356w-63v5-8wf4","Warn: Project is vulnerable to: GHSA-859w-5945-r5v3","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"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-20T15:50:18.054Z","repository_id":38384782,"created_at":"2025-08-20T15:50:18.054Z","updated_at":"2025-08-20T15:50:18.054Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28642290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T18:04:35.752Z","status":"ssl_error","status_checked_at":"2026-01-21T18:03:55.054Z","response_time":86,"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":["hooks","react","react-hooks","tus","tus-js-client"],"created_at":"2026-01-21T20:45:08.286Z","updated_at":"2026-01-21T20:45:08.356Z","avatar_url":"https://github.com/kqito.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch3 align=\"center\"\u003e\n  use-tus\n\u003c/h3\u003e\n\n\u003cp align=\"center\"\u003e\n  React hooks for resumable file uploads using \u003ca href=\"https://github.com/tus/tus-js-client\"\u003etus\u003c/a\u003e.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/kqito/use-tus/actions/workflows/test.yml\"\u003e\u003cimg src=\"https://github.com/kqito/use-tus/workflows/Test/badge.svg\" alt=\"Build status\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://badge.fury.io/js/use-tus\"\u003e\u003cimg src=\"https://badge.fury.io/js/use-tus.svg\" alt=\"Npm version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/kqito/use-tus/blob/main/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/kqito/use-tus\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Features\n- Resumable file uploads in React.\n- Improved file upload management within the React component lifecycle.\n- Lightweight and simple interface hooks.\n- Manage [Upload](https://github.com/tus/tus-js-client/blob/master/docs/api.md#tusuploadfile-options) instances via context.\n- TypeScript support.\n\n## Demo\nTry out the [use-tus demo](https://kqito.github.io/use-tus/?path=/story/usetus--basic).\n\n\n## Installation\nInstall the package using your package manager of choice.\n\n```sh\nnpm install use-tus tus-js-client\n```\n\n## Usage\nBelow is an example of how to use `useTus`.\n\n```tsx\nimport { useTus } from 'use-tus'\n\nconst Uploader = () =\u003e {\n  const { upload, setUpload, isSuccess, error, remove } = useTus();\n\n  const handleSetUpload = useCallback((event: ChangeEvent\u003cHTMLInputElement\u003e) =\u003e {\n    const file = event.target.files.item(0);\n    if (!file) return;\n\n    setUpload(file, {\n      endpoint: 'https://tusd.tusdemo.net/files/',\n      metadata: {\n        filename: file.name,\n        filetype: file.type,\n      },\n    });\n  }, [setUpload]);\n\n  const handleStart = useCallback(() =\u003e {\n    if (upload) upload.start();\n  }, [upload]);\n\n  return (\n    \u003cdiv\u003e\n      \u003cinput type=\"file\" onChange={handleSetUpload} /\u003e\n      \u003cbutton type=\"button\" onClick={handleStart}\u003eUpload\u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n\n## API\n### `useTus` hooks\n\n```tsx\nconst { upload, setUpload, isSuccess, isAborted, isUploading, error, remove } = useTus({ autoAbort, autoStart, uploadOptions, Upload });\n```\n\n`useTus` is a hooks that creates an object to perform Resumable file upload.\n\n### Arguments\n- `autoAbort` (type: `boolean | undefined`) (default: true)\n  - Whether or not to automatically abort uploads when useTus hooks is unmounted.\n\n- `autoStart` (type: `boolean | undefined`) (default: false)\n  - Whether or not to start upload the file after `setUpload` function.\n\n- `uploadOptions` (type: `TusHooksUploadFnOptions | undefined`) (default: undefined)\n  - Option to used by upload object that generated by that hooks.\n\n- `Upload` (type: `Upload | undefined`) (default: undefined)\n  - Option to specify customized own Upload class with this hooks.\n\n#### `uploadOptions`\nThis option extends the `UploadOptions` provided by `tus-js-client`, allowing every callback to receive the upload instance as the final argument. For detailed type information on `UploadOptions`, see [here](https://github.com/tus/tus-js-client/blob/master/lib/index.d.ts#L22).\n\nExample:\n\n```ts\nsetUpload(file, {\n  onSuccess: (upload) =\u003e {\n    console.log(upload.url)\n  },\n  onError: (error, upload) =\u003e {\n    console.log(error)\n    setTimeout(() =\u003e {\n      upload.start()\n    }, 1000)\n  }\n});\n```\n\n\n#### Returns\n- `upload` (type: `tus.Upload | undefined`)\n  - Used for resumable file uploads. Undefined unless `setUpload` is called.\n  - For detailed usage, see [here](https://github.com/tus/tus-js-client#example).\n\n- `setUpload` (type: `(file: tus.Upload['file'], options?: TusHooksUploadFnOptions) =\u003e void`)\n  - Function to create an `Upload`. `uploadOptions` properties are overwritten if `options` is specified.\n\n- `isSuccess` (type: `boolean`)\n  - Indicates if the upload was successful.\n\n- `isAborted` (type: `boolean`)\n  - Indicates if the upload was aborted.\n\n- `isUploading` (type: `boolean`)\n  - Indicates if an upload is in progress.\n\n- `error` (type: `Error | undefined`)\n  - Error when the upload fails.\n\n- `remove` (type: `() =\u003e void`)\n  - Function to reset states.\n\n### `useTusStore` hooks\n\n```tsx\nconst { upload, setUpload, isSuccess, isAborted, isUploading, error, remove } = useTusStore(cacheKey, { autoAbort, autoStart, uploadOptions, Upload });\n```\n\n`useTusStore` creates an object for resumable file uploads and stores it in a context. This is useful for handling uploads across components or pages.\n\n\u003e [!NOTE]\n\u003e `useTusStore` requires `TusClientProvider` as a parent or higher element.\n\n#### Arguments\n- `cacheKey` (type: `string`)\n  - Key associated with the `Upload` object created by `setUpload`.\n\n- `autoAbort` (type: `boolean | undefined`, default: `true`)\n  - Automatically abort uploads when `useTusStore` is unmounted.\n\n- `autoStart` (type: `boolean | undefined`, default: `false`)\n  - Automatically start the upload after calling the `setUpload` function.\n\n- `uploadOptions` (type: `TusHooksUploadFnOptions | undefined`, default: `undefined`)\n  - Set options to be used by the upload object generated by this hook.\n\n- `Upload` (type: `Upload | undefined`, default: `undefined`)\n  - Specify a customized `Upload` class with this hook.\n\n#### Returns\n- `upload` (type: `tus.Upload | undefined`)\n  - Used for resumable file uploads. Undefined unless `setUpload` is called.\n  - Corresponds to the `Upload` associated with `cacheKey` in `TusClientProvider`.\n\n- `setUpload` (type: `(file: tus.Upload['file'], options?: TusHooksUploadFnOptions) =\u003e void`)\n  - Function to create an `Upload`. `uploadOptions` properties are overwritten if `options` is specified.\n\n- `isSuccess` (type: `boolean`)\n  - Indicates if the upload was successful.\n\n- `isAborted` (type: `boolean`)\n  - Indicates if the upload was aborted.\n\n- `isUploading` (type: `boolean`)\n  - Indicates if an upload is in progress.\n\n- `error` (type: `Error | undefined`)\n  - Error when the upload fails.\n\n- `remove` (type: `() =\u003e void`)\n  - Function to delete the `Upload` associated with `cacheKey`.\n\n### `TusClientProvider`\n\n```tsx\n() =\u003e (\n  \u003cTusClientProvider defaultOptions={defaultOptions}\u003e\n    {children}\n  \u003c/TusClientProvider\u003e\n)\n```\n\n`TusClientProvider` stores `Upload` objects created with `useTusStore`.\n\n#### Props\n- `defaultOptions` (type: `(file: tus.Upload['file']) =\u003e TusHooksUploadFnOptions | undefined`)\n  - Default options object used when creating new uploads. For more details, see [here](https://github.com/tus/tus-js-client/blob/master/docs/api.md#tusdefaultoptions).\n\n### `useTusClient`\n\n```tsx\nconst { state, removeUpload, reset } = useTusClient();\n```\n\n`useTusClient` retrieves and resets the state of `TusClientProvider`.\n\n#### Returns\n- `state` (type: `{ [cacheKey: string]: UploadState | undefined }`)\n  - Upload information associated with `cacheKey`.\n\n- `removeUpload` (type: `(cacheKey: string) =\u003e void`)\n  - Remove the upload instance associated with `cacheKey`.\n\n- `reset` (type: `() =\u003e void`)\n  - Initialize the value of `TusClientProvider`.\n\n## Examples\nHere are some examples of how to use `use-tus`.\n\n### Uploading a file\nUse `setUpload` and `upload.start` functions to perform resumable file uploads.\n\n```tsx\nimport { useTus } from 'use-tus'\n\nconst Uploader = () =\u003e {\n  const { upload, setUpload } = useTus();\n\n  const handleSetUpload = useCallback((event: ChangeEvent\u003cHTMLInputElement\u003e) =\u003e {\n    const file = event.target.files.item(0);\n    if (!file) return;\n\n    setUpload(file, {\n      endpoint: 'https://tusd.tusdemo.net/files/',\n      metadata: {\n        filename: file.name,\n        filetype: file.type,\n      },\n    });\n  }, [setUpload]);\n\n  const handleStart = useCallback(() =\u003e {\n    if (upload) upload.start();\n  }, [upload]);\n\n  return (\n    \u003cdiv\u003e\n      \u003cinput type=\"file\" onChange={handleSetUpload} /\u003e\n      \u003cbutton type=\"button\" onClick={handleStart}\u003eUpload\u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n\u003e [!TIP]\n\u003e You can also set `autoStart` to automatically start uploading files after `setUpload` is called.\n\n```tsx\nimport { useTus } from 'use-tus'\n\nconst Uploader = () =\u003e {\n  const { upload, setUpload } = useTus({ autoStart: true });\n\n  const handleSetUpload = useCallback((event: ChangeEvent\u003cHTMLInputElement\u003e) =\u003e {\n    const file = event.target.files.item(0);\n    if (!file) return;\n\n    setUpload(file, {\n      endpoint: 'https://tusd.tusdemo.net/files/',\n      metadata: {\n        filename: file.name,\n        filetype: file.type,\n      },\n    });\n  }, [setUpload]);\n\n  return (\n    \u003cinput type=\"file\" onChange={handleSetUpload} /\u003e\n  );\n};\n```\n\n### Aborting a File Upload\nUse the `upload.abort` function to abort an upload.\n\n```tsx\nimport { useTus } from 'use-tus'\n\nconst Aborter = () =\u003e {\n  const { upload } = useTus();\n\n  const handleAbort = useCallback(() =\u003e {\n    if (upload) upload.abort();\n  }, [upload]);\n\n  return (\n    \u003cdiv\u003e\n      \u003cbutton type=\"button\" onClick={handleAbort}\u003eAbort\u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n### Default Options for Upload\nSpecify default options in `defaultOptions` props of the `TusClientProvider`.\n\n```tsx\nimport { useTusStore, DefaultOptions, TusClientProvider } from 'use-tus'\n\nconst defaultOptions: DefaultOptions = (file) =\u003e ({\n  endpoint: 'https://tusd.tusdemo.net/files/',\n  metadata:\n    file instanceof File\n      ? {\n          filename: file.name,\n          filetype: file.type,\n        }\n      : undefined,\n});\n\nconst App = () =\u003e (\n  \u003cTusClientProvider defaultOptions={defaultOptions}\u003e\n    \u003cUploader /\u003e\n  \u003c/TusClientProvider\u003e\n);\n\nconst Uploader = () =\u003e {\n  const { setUpload } = useTusStore('cacheKey', { autoStart: true });\n\n  const handleSetUpload = useCallback((event: ChangeEvent\u003cHTMLInputElement\u003e) =\u003e {\n    const file = event.target.files.item(0);\n    if (!file) return;\n\n    // Uploads the selected file using default options.\n    // Overrides if options are provided to setUpload.\n    setUpload(file);\n  }, [setUpload]);\n\n  return \u003cinput type=\"file\" onChange={handleSetUpload} /\u003e;\n};\n```\n\n### Specify Upload Key\nSpecify `cacheKey` to associate uploads across components/pages.\n\n```tsx\nimport { useTusStore } from 'use-tus'\n\nconst SelectFileComponent = (file: File) =\u003e {\n  const { setUpload } = useTusStore('upload-thumbnail');\n  setUpload(file);\n};\n\nconst UploadFileComponent = () =\u003e {\n  const { upload } = useTusStore('upload-thumbnail');\n  if (upload) upload.start();\n};\n```\n\n## License\n[MIT © kqito](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkqito%2Fuse-tus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkqito%2Fuse-tus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkqito%2Fuse-tus/lists"}