Use Tus Versions Save

React hooks for resumable file uploads using tus

v0.8.1

4 months ago

Changes in v0.8.1

tus-js-client Update

In this release, we've updated the tus-js-client version of peerDependencies to >=2.2.0 and resolving issue #38. Importantly, no APIs or interfaces have been modified with this update, ensuring a smooth transition for our users. If you have any issues or suggestions, please let us know. We're always looking forward to your feedback!

v0.8.0

5 months ago

Overview

In this minor patch release of use-tus, I have made several improvements and changes to enhance the usability and flexibility of the library. The key changes include updates to re-rendering logic, modifications to callback handling, and the addition of new state and property arguments for hooks.

Details

Re-rendering when the url field is changed

In this release, I have updated the re-rendering logic to respond to changes in the url field of the upload instance. Previously, I avoided re-rendering due to concerns of excessive rendering. However, I now allow re-rendering when the url field is changed to accommodate cases where the url needs to be referred according to the react lifecycle. Example:

  useEffect(() => {
    console.log("useEffect", upload?.url);
  }, [upload?.url]);

Referencing upload within callback

Previously, it was not possible to refer to upload within callbacks such as onSuccess in useTus hooks and useTusStore hooks unless useRef was used. In this release, I have made modifications to allow receiving the upload instance as the last argument of various callbacks. Example:

setUpload(file, {
  onSuccess: (upload) => {
    console.log(upload.url)
  },
  onError: (error, upload) => {
    console.log(error)
    setTimeout(() => {
      upload.start()
    }, 1000)
  }
})

Additional Changes

  • I have removed some types exported from 'tus-js-client' as 'tus-js-client' has been already defined as peerDependencies.
  • A new isUploading state has been added which will be true when uploading with tus, and false otherwise.
  • I now support passing Upload property arguments for useTus and useTusStore hooks. This is useful for using a customized own Upload class with useTus.
  • Some hooks types have been renamed for better clarity. UseTusUseTusResult has been renamed to TusHooksResult and UseTusOptions to TusHooksOptions.

v0.7.3

6 months ago

Overview

v0.7.2

6 months ago

Overview

v0.7.1

1 year ago

Overview

v0.7.0

1 year ago

Update

Add support for react version to v18

Changed peerDependencies for use-tus to >=16.8. This will fix issues like https://github.com/kqito/use-tus/issues/35.

Also, there is no interface changes.

Bug fixs

Change isAbort will be false after remove function is called.

Change the behavior when the remove function of useTus hooks is called. Until now, calling the remove function initialized the state and then set isAbort to true. Therefore, the state after calling the remove function was different from the initial value.

So, we will change it so that isAbort remains false after calling the remove function.

Change setUpload function will reset state.

Changed so that isAborted, isSuccess, etc. are initialized when the setUpload function of the useTus hooks is called.

Misc

  • Use FC type instead of VFC to stories components
  • Remove @testing-library/react-hooks from dependencies

v0.6.1

1 year ago

Overview

Thank you !!

v0.6.0

2 years ago

Overview

By https://github.com/kqito/use-tus/pull/31

  • Remove the useTus function to save to store using cacheKey
  • Add useTusStore hooks that has to save to store functionality.
  • Remove invalid props canStoreUrls from TusClientProvider

Migrating from 0.5 to 0.6

If you use cacheKey options in useTus hooks

The useTus hooks have been removed the state management functionality using TusClientProvider and cacheKey option.

Therefore, if you are currently using useTus hooks with cacheKey option, you will need to change to use the newly added useTusStore hooks.

import { useTusStore } from 'use-tus'

// Old usage
const { upload } = useTus({ cacheKey: 'hogehoge', autoAbort: true })

// New usage
const { upload } = useTusStore('hogehoge', { autoAbort: true })

The return value of each hooks is the same, so there is no need to make any other changes

If you not use cacheKey options in useTus hooks

If you are using use-tus and not using the cacheKey option, you no longer need to specify TusClientProvider.

So please consider removing TusClientProvider from the parent comport if necessary.

v0.5.0

2 years ago

Overview

  • Move tus-js-client from dependencies to peerDependencies
  • Fix to use createElement instead of JSX for support even react 16.x
  • Update README.md about installation

Upgrading from 0.4 to 0.5

Install tus-js-client

  • we have to install tus-js-client for using use-tus as first.
npm install tus-js-client

or

yarn add tus-js-client
  • Also, there is no need to rewrite the code.

v0.3.0

2 years ago

Overview

  • Update defaultOptions props of TusClientProvider to function. (#28)
  • Add some examples to README.md

About defaultOptions props of TusClientProvider

Previously, the type of defaultOptions props is just object.

But It allowed you to intuitively specify default options, but it did not allow you to specify the default options associated with the you want to upload.

For this reason, I changed defaultOptions to allow to be specified as follows.

const defaultOptions: DefaultOptions = (contents) => {
  const file = contents instanceof File ? contents : undefined;

  return {
    endpoint: 'https://example.com',
    metadata: file
      ? {
          filename: file.name,
          filetype: file.type,
        }
      : undefined,
  };
};

export const App = () => (
  <TusClientProvider defaultOptions={defaultOptions}>
    <Uploader />
  </TusClientProvider>
);

If you think this library looks good, please star it!