"use client" import { useMemo, useRef } from "react" export function useDedupedItems( items: T[], itemKey?: (item: T | undefined, index: number) => string | number | undefined, ): T[] { // Use ref to avoid dependency changes causing re-renders const itemKeyRef = useRef(itemKey) itemKeyRef.current = itemKey return useMemo(() => { const seenKeys = new Set() return items.filter((item, index) => { const key = itemKeyRef.current?.(item, index) ?? index if (seenKeys.has(key)) { return false } seenKeys.add(key) return true }) }, [items]) }