Files
wanderer/assets/js/hooks/Mapper/mapRootProvider/hooks/api/useCommandPings.ts
2025-07-18 13:39:36 +02:00

24 lines
744 B
TypeScript

import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
import { CommandPingAdded, CommandPingCancelled } from '@/hooks/Mapper/types';
import { useCallback, useRef } from 'react';
export const useCommandPings = () => {
const {
update,
data: { pings },
} = useMapRootState();
const ref = useRef({ update, pings });
ref.current = { update, pings };
const pingAdded = useCallback((pings: CommandPingAdded) => {
ref.current.update({ pings });
}, []);
const pingCancelled = useCallback(({ type, id }: CommandPingCancelled) => {
const newPings = ref.current.pings.filter(x => x.id !== id && x.type !== type);
ref.current.update({ pings: newPings });
}, []);
return { pingAdded, pingCancelled };
};