MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useListState

Function useListState

packages/react-stately/src/list/useListState.ts:50–83  ·  view source on GitHub ↗
(props: ListProps<T>)

Source from the content-addressed store, hash-verified

48 * of items from props, and manages multiple selection state.
49 */
50export function useListState<T>(props: ListProps<T>): ListState<T> {
51 let {filter, layoutDelegate} = props;
52
53 let selectionState = useMultipleSelectionState(props);
54 let disabledKeys = useMemo(
55 () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),
56 [props.disabledKeys]
57 );
58
59 let factory = useCallback(
60 nodes =>
61 filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>),
62 [filter]
63 );
64 let context = useMemo(
65 () => ({suppressTextValueWarning: props.suppressTextValueWarning}),
66 [props.suppressTextValueWarning]
67 );
68
69 let collection = useCollection(props, factory, context);
70
71 let selectionManager = useMemo(
72 () => new SelectionManager(collection, selectionState, {layoutDelegate}),
73 [collection, selectionState, layoutDelegate]
74 );
75
76 useFocusedKeyReset(collection, selectionManager);
77
78 return {
79 collection,
80 disabledKeys,
81 selectionManager
82 };
83}
84
85/**
86 * Filters a collection using the provided filter function and returns a new ListState.

Callers 15

renderActionGroupHookFunction · 0.90
ListFunction · 0.90
SelectableListFunction · 0.90
GridFunction · 0.90
DraggableCollectionFunction · 0.90
ReorderableGridFunction · 0.90
DroppableGrid.tsxFile · 0.90
DraggableListBoxFunction · 0.90
DraggableCollectionFunction · 0.90

Calls 4

useCollectionFunction · 0.90
useFocusedKeyResetFunction · 0.85
filterFunction · 0.50

Tested by 1

renderActionGroupHookFunction · 0.72