onsitesurvey/src/hooks/useCommCode.ts

20 lines
540 B
TypeScript

import { useAxios } from './useAxios'
import type { CommCode } from '@/types/CommCode'
export function useCommCode() {
const { axiosInstance } = useAxios()
const getCommCode = async (headCode: string): Promise<CommCode[]> => {
try {
const response = await axiosInstance(null).get<CommCode[]>('/api/comm-code', { params: { headCode: headCode } })
return response.data
} catch (error) {
console.error(`common code (${headCode}) load failed:`, error)
return []
}
}
return {
getCommCode,
}
}