-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuseCreateSubGoal.ts
More file actions
31 lines (26 loc) · 948 Bytes
/
useCreateSubGoal.ts
File metadata and controls
31 lines (26 loc) · 948 Bytes
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
28
29
30
31
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { createSubGoal } from '../index';
import type { CreateSubGoalRequest } from '../type/createSubGoal';
export const useCreateSubGoal = (coreGoalId: number) => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (request: CreateSubGoalRequest) => createSubGoal(coreGoalId, request),
onSuccess: (data) => {
console.log('하위 목표 생성 성공:', data.id);
// 하위 목표 ID 리스트 캐시 갱신
queryClient.invalidateQueries({
queryKey: ['subGoalIds', coreGoalId],
exact: true,
refetchType: 'active',
});
// 하위 목표 전체 조회 캐시도 갱신
queryClient.invalidateQueries({
queryKey: ['subGoals'],
refetchType: 'active',
});
},
onError: (error) => {
console.error('하위 목표 생성 실패:', error);
},
});
};