Skip to main content

useBatchStartListener

Package​

@rpldy/uploady

Installation​

npm install @rpldy/uploady

Details​

type BatchStartHook = (cb: (batch: Batch, options: CreateOptions) =>
PreSendResponse | Promise<PreSendResponse>) => void;
note

Event Hook - BATCH-START

Called when batch items start uploading

The callback passed to the hook may also return an object containing items and/or options in order to update the request dynamically, similar to useRequestPreSend only for the entire batch. See withBatchStartUpdate HOC below for more details.

info

This event is cancellable

info

This event can be scoped to a specific batch by passing the batch id as a second parameter

Example​

import { useBatchStartListener } from "@rpldy/uploady";

const MyComponent = () => {
useBatchStartListener((batch, options) => {
console.log(`batch ${batch.id} started uploading`);
});

//or scoped:
useBatchStartListener((batch) => {
console.log(`batch ${batch.id} started uploading`);
}, "b-123");
//...
};

Cancel Batch​

import { useBatchStartListener } from "@rpldy/uploady";

const MyComponent = () => {
useBatchStartListener(() => {
return false;
});
};

Update Batch Options​

import { useBatchStartListener } from "@rpldy/uploady";
const MyComponent = () => {
useBatchStartListener((batch, options) => {
return {
options: {
destination: {
headers: {
"x-custom":
options.destination.headers["x-custom"] + " updated",
}
}
}
}
});
};