Files
Compass/web/hooks/use-other-answers.ts
2026-02-23 14:48:03 +01:00

31 lines
782 B
TypeScript

import {User} from 'common/user'
import {useEffect} from 'react'
import {usePersistentInMemoryState} from 'web/hooks/use-persistent-in-memory-state'
import {getOtherAnswers} from 'web/lib/supabase/answers'
export type OtherAnswersType = {
question_id: number
created_time: number
free_response: string
multiple_choice: number
integer: number
age: number
gender: string
city: string
data: User
}
export const useOtherAnswers = (question_id: number) => {
const [otherAnswers, setOtherAnswers] = usePersistentInMemoryState<
OtherAnswersType[] | null | undefined
>(undefined, 'other_answer_' + question_id)
useEffect(() => {
getOtherAnswers(question_id).then((data) => {
setOtherAnswers(data)
})
}, [question_id])
return otherAnswers
}