| 57 | * @returns - The selected elements. |
| 58 | */ |
| 59 | export function useElements< |
| 60 | Elements extends GraphElement = GraphElement, |
| 61 | SelectorReturnType = Elements[], |
| 62 | >( |
| 63 | selector: ( |
| 64 | items: CellMap<Elements> |
| 65 | ) => SelectorReturnType = defaultSelector as () => SelectorReturnType, |
| 66 | isEqual: (a: SelectorReturnType, b: SelectorReturnType) => boolean = util.isEqual |
| 67 | ): SelectorReturnType { |
| 68 | const { subscribe, getElements } = useGraphStore(); |
| 69 | const typedGetElements = getElements as () => CellMap<Elements>; |
| 70 | const elements = useSyncExternalStoreWithSelector( |
| 71 | subscribe, |
| 72 | typedGetElements, |
| 73 | typedGetElements, |
| 74 | selector, |
| 75 | isEqual |
| 76 | ); |
| 77 | return elements; |
| 78 | } |