{"version":3,"sources":["../../src/use-creation/index.ts"],"sourcesContent":["import { useRef } from 'react'\nimport { deepEqual } from '../utils/equal'\n\nimport type { DependencyList } from 'react'\n\ninterface CreationRefState<T> {\n  value?: T\n  created?: boolean\n  preDeps?: DependencyList\n}\n\n/**\n * A React Hook that creates a memoized value that only re-create when the dependencies change.\n */\nexport function useCreation<T>(create: () => T, currDeps?: DependencyList): T {\n  const { current: creation } = useRef<CreationRefState<T>>({})\n\n  if (!creation.created || !deepEqual(creation.preDeps, currDeps)) {\n    creation.value = create()\n    creation.created = true\n    creation.preDeps = currDeps\n  }\n\n  return creation.value as T\n}\n"],"names":["useCreation","create","currDeps","useRef","current","creation","created","deepEqual","preDeps","value"],"mappings":";;;;+BAcgBA;;;eAAAA;;;qBAdO;qBACG;AAanB,SAASA,YAAeC,MAAe,EAAEC,QAAyB;IACvE,IAA8BC,UAAAA,IAAAA,aAAM,EAAsB,CAAC,IAAnDC,AAASC,WAAaF,QAAtBC;IAER,IAAI,CAACC,SAASC,OAAO,IAAI,CAACC,IAAAA,gBAAS,EAACF,SAASG,OAAO,EAAEN,WAAW;QAC/DG,SAASI,KAAK,GAAGR;QACjBI,SAASC,OAAO,GAAG;QACnBD,SAASG,OAAO,GAAGN;IACrB;IAEA,OAAOG,SAASI,KAAK;AACvB"}