useBatchStartListener
Packageβ
Installationβ
- npm
- Yarn
- pnpm
npm install @rpldy/uploady
yarn add @rpldy/uploady
pnpm add @rpldy/uploady
Detailsβ
type BatchStartHook = (cb: (batch: Batch, options: CreateOptions) =>
PreSendResponse | Promise<PreSendResponse>) => void;
- See: CreateOptions
- See; PreSendResponse
- See: Batch Entity
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",
}
}
}
}
});
};