All files / src/hooks/cache useInvalidateChildTaskCache.ts

50% Statements 1/2
100% Branches 0/0
100% Functions 0/0
50% Lines 1/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23                        8906x                    
import { enhancedAPI } from "@/api/enhanceEndpoints.ts";
import { useAppDispatch } from "@/store/hooks.ts";
 
/**
 * Returns a callback that invalidates all cached child-task pages for a
 * parent task.
 *
 * RTK Query refetches any actively mounted page for that parent and evicts
 * inactive pages from cache, so previously viewed pages are only retrieved
 * again if the user remounts them later.
 */
export function useInvalidateChildTaskCache() {
  const dispatch = useAppDispatch();
 
  return (parentTaskId: number) => {
    dispatch(
      enhancedAPI.util.invalidateTags([
        { type: "TaskChildren", id: parentTaskId },
      ]),
    );
  };
}