Skip to content

Core API Reference

The @survey-kit/core package provides the fundamental building blocks for creating and managing surveys.

Installation

npm install @survey-kit/core

Hooks

useSurvey

The main hook for initialising and managing survey state.

import { useSurvey } from '@survey-kit/core'

const survey = useSurvey(config)

Parameters:

  • config (SurveyConfig): Survey configuration object

Returns:

  • Survey instance with state and methods

Example:

const survey = useSurvey({
  id: 'my-survey',
  title: 'Customer Feedback',
  questions: [...]
});

Components

SurveyRenderer

Main component for rendering the survey interface.

import { SurveyRenderer } from '@survey-kit/core';

<SurveyRenderer
  survey={survey}
  onComplete={handleComplete}
  onProgress={handleProgress}
/>

Props:

Prop Type Required Description
survey Survey Yes Survey instance from useSurvey
onComplete (data: SurveyData) => void Yes Callback when survey is completed
onProgress (progress: number) => void No Callback for progress updates

Types

SurveyConfig

The main configuration interface for defining surveys.

interface SurveyConfig {
  id: string
  title: string
  description?: string
  questions: Question[]
  settings?: SurveySettings
}

Question

Interface for individual questions.

interface Question {
  id: string
  type: QuestionType
  question: string
  required?: boolean
  validation?: ValidationRule
  options?: Option[]
  placeholder?: string
}

QuestionType

Supported question types:

type QuestionType =
  | 'text'
  | 'email'
  | 'number'
  | 'textarea'
  | 'radio'
  | 'checkbox'
  | 'select'
  | 'date'

SurveySettings

Configuration for survey behavior:

interface SurveySettings {
  showProgress?: boolean
  allowBack?: boolean
  submitButtonText?: string
  theme?: string
  mobileOptimized?: boolean
}

Validation

Detailed validation API documentation coming soon.

State Management

Detailed state management documentation coming soon.

Advanced Usage

Custom Question Types

Documentation for creating custom question types coming soon.

Persistence

Documentation for saving and restoring survey progress coming soon.

Examples

For complete working examples, see the template package.

Migration Guide

Migration guide for version updates coming soon.

API Changelog

API changes and deprecations will be documented here.