Context
useJobRun supports onStart, onComplete, onFail callbacks, but createJobHooks wraps it as:
useRun: (runId: string | null) => {
return useJobRun<InferOutput<TJob>>({ api, runId })
}
The callbacks are not exposed through the generated useRun hook.
Problem
When persisting runId across page reloads (e.g. via URL search params), consumers need to clear the persisted ID when the run reaches a terminal state. Without onComplete/onFail, they must use a useEffect watching isCompleted/isFailed, which is less clean:
const { runId, clearRunId } = usePersistedRunId('refreshRunId', fetcherRunId)
const { isCompleted, isFailed, ...rest } = durably.crawl.useRun(runId)
// Would be cleaner as: durably.crawl.useRun(runId, { onComplete: clearRunId })
useEffect(() => {
if (isCompleted || isFailed) clearRunId()
}, [isCompleted, isFailed, clearRunId])
Proposed Change
Add optional second argument to the generated useRun:
useRun: (runId: string | null, options?: { onStart?: () => void; onComplete?: () => void; onFail?: () => void }) => {
return useJobRun<InferOutput<TJob>>({ api, runId, ...options })
}
This is backward-compatible — existing callers without options continue to work.
Context
useJobRunsupportsonStart,onComplete,onFailcallbacks, butcreateJobHookswraps it as:The callbacks are not exposed through the generated
useRunhook.Problem
When persisting
runIdacross page reloads (e.g. via URL search params), consumers need to clear the persisted ID when the run reaches a terminal state. WithoutonComplete/onFail, they must use auseEffectwatchingisCompleted/isFailed, which is less clean:Proposed Change
Add optional second argument to the generated
useRun:This is backward-compatible — existing callers without options continue to work.