React hooks for resumable file uploads using tus
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!
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.
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]);
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)
}
})
isUploading
state has been added which will be true when uploading with tus, and false otherwise.UseTusUseTusResult
has been renamed to TusHooksResult
and UseTusOptions
to TusHooksOptions
.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.
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.
setUpload
function will reset state.Changed so that isAborted, isSuccess, etc. are initialized when the setUpload function of the useTus hooks is called.
FC
type instead of VFC
to stories components@testing-library/react-hooks
from dependencieschildren
type of TusClientProvider
on react v18. https://github.com/kqito/use-tus/pull/33 @kallebysantosThank you !!
By https://github.com/kqito/use-tus/pull/31
useTus
function to save to store using cacheKey
useTusStore
hooks that has to save to store functionality.canStoreUrls
from TusClientProvider
useTus
hooksThe 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
useTus
hooksIf 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.
createElement
instead of JSX for support even react 16.xtus-js-client
tus-js-client
for using use-tus as first.npm install tus-js-client
or
yarn add tus-js-client
defaultOptions
props of TusClientProvider
to function. (#28)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!