import { useState } from 'react' ; import { useStaticCallback } from '../../../Hooks' ; export type Selection < T > = T [ ] ; export function useSelection < T > ( ) { const [ selection , setSelection ] = useState < T [ ] > ( [ ] ) ; const selectToggle = useStaticCallback ( ( id ) => setSelection ( ( selected ) => selected . includes ( id ) ? selected . filter ( ( filterId ) => filterId !== id ) : [ ... selected , id ] ) ) ; const selectOnly = useStaticCallback ( ( id ) => { setSelection ( [ id ] ) ; } ) ; const selectNone = useStaticCallback ( ( ) => { setSelection ( [ ] ) ; } ) ; return { selection , selectOnly , selectToggle , selectNone } ; }