Skip to content
KajayDocs
IntegrationTypeScript SDK

Save and resume progress

Persist plain progress snapshots and restore respondents without coupling Kajay to storage.

Store a progress snapshot

survey.progress is plain JSON containing answer data and the current page name. Save it after value and page changes, then delete it after completion.

Save and restore progress
import type { SurveyProgress } from '@kajay/core';

function persist(progress: SurveyProgress): void {
  sessionStorage.setItem('survey-progress', JSON.stringify(progress));
}

const stopValue = survey.onValueChanged.add(() => persist(survey.progress));
const stopPage = survey.onCurrentPageChanged.add(() => persist(survey.progress));
const stopComplete = survey.onComplete.add(() => {
  sessionStorage.removeItem('survey-progress');
});

const saved = readAndValidateProgress();
if (saved !== undefined) survey.restore(saved);

Restore before rendering

Restore after parsing and before the first render. Kajay restores answers first so conditional page visibility settles, then navigates by page name rather than a fragile numeric index.

Validate stored data

Autosave policy

Kajay emits deterministic changes but does not debounce, persist, or resolve revisions. The host owns batching, offline queues, optimistic concurrency, encryption, and retention.