Skip to Content

Response Hooks

Hooks for reading and writing quiz/survey response variables (answers.* namespace).

Every response variable must be declared in responses in your appfunnel.config.ts before it can be used. Undeclared keys will be ignored.

useResponse<T>(key)

Read/write a single response variable. This is the primary hook for capturing visitor answers.

const [goal, setGoal] = useResponse<string>('goal') const [interests, setInterests] = useResponse<string[]>('interests')
ReturnTypeDescription
[0]TCurrent response value
[1](value: T) => voidSetter function

useResponses()

Returns all response variables as a flat object with the answers. prefix stripped. Only re-renders when an answers.* variable changes.

const responses = useResponses() // { goal: 'weight_loss', interests: ['yoga', 'running'] }
ReturnTypeDescription
responsesRecord<string, VariableValue>All response key-value pairs
Last updated on