Spaces:
Sleeping
Sleeping
File size: 957 Bytes
68f7925 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import { createQueryOptions } from '@/api-client/query-config';
import type { ThemeExtractionResult } from '@/schema/theme-extraction';
import { useQuery } from '@tanstack/react-query';
import { generateThemeCss, type GenerateThemeCssResponse } from './index';
/**
* テーマCSS生成フック
* テーマデータが渡された場合のみCSS生成を実行
*/
export function useThemeCss(themeData: ThemeExtractionResult | null, enabled: boolean = true) {
return useQuery<GenerateThemeCssResponse>({
...createQueryOptions<GenerateThemeCssResponse>(),
queryKey: ['themeCss', themeData ? JSON.stringify(themeData) : 'no-theme'],
queryFn: () => {
if (!themeData) {
return {
success: true,
css: undefined,
};
}
return generateThemeCss(themeData);
},
enabled: enabled && !!themeData,
staleTime: Infinity, // テーマデータが同じならキャッシュを使う
});
}
|