| 1 |
import { getSiteQuestions } from '@launch/api/DataApi'; |
| 2 |
import { useSiteProfile } from '@launch/hooks/useSiteProfile'; |
| 3 |
import useSWRImmutable from 'swr/immutable'; |
| 4 |
|
| 5 |
export const useSiteQuestions = ({ disableFetch = false } = {}) => { |
| 6 |
const { siteProfile, loading: profileLoading } = useSiteProfile(); |
| 7 |
|
| 8 |
const { data, error } = useSWRImmutable( |
| 9 |
profileLoading || !siteProfile || disableFetch |
| 10 |
? null |
| 11 |
: { |
| 12 |
key: 'site-questions', |
| 13 |
siteProfile, |
| 14 |
}, |
| 15 |
getSiteQuestions, |
| 16 |
); |
| 17 |
|
| 18 |
return { |
| 19 |
questions: data, |
| 20 |
error, |
| 21 |
loading: profileLoading || (!data && !error), |
| 22 |
}; |
| 23 |
}; |
| 24 |
|