import { useMutationState } from '@tanstack/react-query' import { useMemo } from 'react' type DeletableResourceEvent = 'deleteAttachment' | 'deleteMessage' export function useDeletingIds(event: DeletableResourceEvent): Set { const ids = useMutationState({ filters: { mutationKey: [event], status: 'pending', }, select: mutation => { // Extract the item ID from the mutation key: [ event, id ] const key = mutation.options.mutationKey return key && Array.isArray(key) && typeof key[1] === 'string' ? key[1] : null }, }) return useMemo(() => { return new Set(ids.filter(id => id !== null)) }, [ids]) }