import { useLocation } from 'react-router-dom' import PrefetchLink from '@/components/PrefetchLink' export default ({ by, label, currentOrder, defaultDirection }: { by: T label: string currentOrder: `${ T }:${ 'asc' | 'desc' }` defaultDirection: Record }) => { const [fld, dir] = currentOrder.split (':') const location = useLocation () const qs = new URLSearchParams (location.search) const nextDir = (by === fld) ? (dir === 'asc' ? 'desc' : 'asc') : (defaultDirection[by] || 'desc') qs.set ('order', `${ by }:${ nextDir }`) qs.set ('page', '1') return ( {label} {by === fld && (dir === 'asc' ? ' ▲' : ' ▼')} ) }