{"version":3,"file":"useCreateAtom.cjs","names":[],"sources":["../src/useCreateAtom.ts"],"sourcesContent":["import { useState } from 'preact/hooks'\nimport { createAtom } from '@tanstack/store'\n// eslint-disable-next-line no-duplicate-imports\nimport type { Atom, AtomOptions, ReadonlyAtom } from '@tanstack/store'\n\n/**\n * Creates a stable atom instance for the lifetime of the component.\n *\n * Pass an initial value to create a writable atom, or a getter function to\n * create a readonly derived atom. This mirrors {@link createAtom}, but only\n * creates the atom once per component mount.\n *\n * @example\n * ```tsx\n * function Counter() {\n *   const countAtom = useCreateAtom(0)\n *   const [count, setCount] = useAtom(countAtom)\n *\n *   return (\n *     <button type=\"button\" onClick={() => setCount((prev) => prev + 1)}>\n *       {count}\n *     </button>\n *   )\n * }\n * ```\n */\nexport function useCreateAtom<T>(\n  getValue: (prev?: NoInfer<T>) => T,\n  options?: AtomOptions<T>,\n): ReadonlyAtom<T>\nexport function useCreateAtom<T>(\n  initialValue: T,\n  options?: AtomOptions<T>,\n): Atom<T>\nexport function useCreateAtom<T>(\n  valueOrFn: T | ((prev?: T) => T),\n  options?: AtomOptions<T>,\n): Atom<T> | ReadonlyAtom<T> {\n  const [atom] = useState<Atom<T> | ReadonlyAtom<T>>(() => {\n    if (typeof valueOrFn === 'function') {\n      return createAtom(valueOrFn as (prev?: NoInfer<T>) => T, options)\n    }\n\n    return createAtom(valueOrFn, options)\n  })\n\n  return atom\n}\n"],"mappings":";;;;AAkCA,SAAgB,cACd,WACA,SAC2B;CAC3B,MAAM,CAAC,yCAAkD;AACvD,MAAI,OAAO,cAAc,WACvB,wCAAkB,WAAuC,QAAQ;AAGnE,yCAAkB,WAAW,QAAQ;GACrC;AAEF,QAAO"}