()
| 103 | * ---------------------------------------------------------------------------------------------*/ |
| 104 | |
| 105 | function useCollection() { |
| 106 | const context = useCollectionContext() |
| 107 | |
| 108 | const getItems = React.useCallback(() => { |
| 109 | const collectionNode = context.collectionRef.current |
| 110 | if (!collectionNode) return [] |
| 111 | const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`)) |
| 112 | const items = Array.from(context.itemMap.values()) |
| 113 | const orderedItems = items.sort( |
| 114 | (a, b) => orderedNodes.indexOf(a.ref.current!) - orderedNodes.indexOf(b.ref.current!), |
| 115 | ) |
| 116 | return orderedItems |
| 117 | }, [context.collectionRef, context.itemMap]) |
| 118 | |
| 119 | return getItems |
| 120 | } |
| 121 | |
| 122 | return [ |
| 123 | { Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot }, |
no test coverage detected
searching dependent graphs…