{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAmBM,SAAS,0CACd,KAA8B,EAC9B,OAAgC,EAChC,OAAiB;IAEjB,IAAI,UAAU,CAAA,GAAA,oBAAM,EAAE,IAAM,IAAI,CAAA,GAAA,2CAAgB,KAAU,EAAE;IAC5D,IAAI,YAAC,QAAQ,SAAE,KAAK,cAAE,UAAU,EAAC,GAAG;IACpC,IAAI,SAAS,CAAA,GAAA,oBAAM,EAAE;QACnB,IAAI,YACF,OAAO;QAET,IAAI,QAAQ,QAAQ,KAAK,CAAC;sBAAC;mBAAU;QAAK,GAAG;QAC7C,OAAO,QAAQ;IACjB,GAAG;QAAC;QAAS;QAAU;QAAO;QAAY;QAAS;KAAQ;IAC3D,OAAO;AACT","sources":["packages/react-stately/src/collections/useCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {ReactElement, useMemo} from 'react';\n\ninterface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<\n  CollectionStateBase<T, C>,\n  'children'\n> {\n  children?:\n    | ReactElement<any>\n    | null\n    | (ReactElement<any> | null)[]\n    | ((item: T) => ReactElement<any> | null);\n}\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T, C extends Collection<Node<T>> = Collection<Node<T>>>(\n  props: CollectionOptions<T, C>,\n  factory: CollectionFactory<T, C>,\n  context?: unknown\n): C {\n  let builder = useMemo(() => new CollectionBuilder<any>(), []);\n  let {children, items, collection} = props;\n  let result = useMemo(() => {\n    if (collection) {\n      return collection;\n    }\n    let nodes = builder.build({children, items}, context);\n    return factory(nodes);\n  }, [builder, children, items, collection, context, factory]);\n  return result;\n}\n"],"names":[],"version":3,"file":"useCollection.cjs.map"}