PluginProbe
Extendify / 1.6.1
Extendify v1.6.1
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / Chat / hooks / useAnswer.js

useAnswer.js in Extendify 1.6.1, at src/Chat/hooks/useAnswer.js

27 lines 749 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { getAnswer } from '@chat/api/Data'
2 import useSWR from 'swr'
3
4 export const useAnswer = (questionId, status = null) => {
5 const { data, mutate, error } = useSWR(
6 questionId,
7 async () => {
8 const response = await getAnswer(questionId)
9
10 if (!response?.status) {
11 console.error(response)
12 throw new Error('Bad data')
13 }
14
15 return response
16 },
17 {
18 refreshInterval: status === 'finished' ? 0 : 1_000,
19 revalidateOnFocus: false,
20 revalidateIfStale: status !== 'finished',
21 revalidateOnReconnect: false,
22 },
23 )
24
25 return { data, mutate, error, loading: questionId && !data && !error }
26 }
27