message / frontend /src /hooks /useTools.ts
hunian
feat: 重构前端控制台和工具页面
a43ac26
Raw
History Blame Contribute Delete
663 Bytes
/**
* Tool 目录相关 hooks
*/
import { useQuery } from '@tanstack/react-query';
import { toolsApi } from '@api/tools';
import { ToolQueryParams } from '@typings/tool';
import { QUERY_STALE_TIME } from '@lib/constants';
/**
* 获取 Tool 目录列表
*/
export function useTools(params?: ToolQueryParams) {
return useQuery({
queryKey: ['tools', params],
queryFn: () => toolsApi.list(params),
staleTime: QUERY_STALE_TIME,
});
}
/**
* 获取单个 Tool 详情
*/
export function useTool(toolName: string) {
return useQuery({
queryKey: ['tools', toolName],
queryFn: () => toolsApi.get(toolName),
enabled: !!toolName,
});
}