useSyncsnapJob
useSyncsnapJob creates a transfer job, then calls your backend’s wait endpoint. The server polls until the job completes or fails and returns the final job plus a result (e.g. presigned download URL or a custom payload from your server’s onCompleted callback). The hook passes that result to your onCompleted(job, result). It powers SyncsnapUploadButton and can be used on its own for custom UIs.
Basic usage
- Call start() to create a job and call the wait endpoint (server does the polling).
- jobId is set once the job is created; use it with SyncsnapQrCode or createUploadUrl.
- status is the current job status; isWaiting is true while the wait request is in flight.
- onCompleted(job, result) runs when the job finishes; result is what your server’s
onCompletedreturned, or the presigned download URL when no callback is set.
Options
| Option | Type | Default | Description |
|---|---|---|---|
createJobUrl | string | "/api/syncsnap/job" | URL for POST to create a job. |
getJobUrl | (jobId: string) => string | id => "/api/syncsnap/job/" + id | URL for GET job status. |
getWaitForCompletionUrl | (jobId: string) => string | id => getJobUrl(id) + "/wait" | URL for the server’s wait endpoint (server polls until job completes). |
waitTimeoutMs | number | 120000 | Timeout passed to the wait endpoint (ms). |
waitIntervalMs | number | 2000 | Poll interval passed to the wait endpoint (ms). |
autoStart | boolean | false | If true, call start() once on mount. |
onJobCreated | (job: CreateJobResponse) => void | — | Called when the job is created. |
onCompleted | (job: Job, result?: unknown) => void | — | Called when job completes or fails; result is server’s onCompleted return (or presigned URL). |
onError | (error: Error) => void | — | Called on create or wait errors. |
Return value
| Property | Type | Description |
|---|---|---|
job | Job | null | Current job object, or null before create / after completion. |
jobId | string | null | Job ID when available. |
status | JobStatus | null | Current status. |
error | Error | null | Last error from create or wait. |
isWaiting | boolean | True while the wait request is in flight. |
start | () => Promise<void> | Create job and call wait endpoint. |
reset | () => void | Abort wait, clear state, reset error. |
Custom URLs
Use a different API base path:Wait timeout and interval
The client sendstimeoutMs and intervalMs as query params to the wait endpoint. Override the defaults: