MCPcopy Create free account
hub / github.com/editablejs/editable / useCollection

Function useCollection

packages/ui/src/collection.tsx:105–120  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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 },

Callers 1

menu.tsxFile · 0.85

Calls 1

useCollectionContextFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…