{"version":3,"file":"useCreateAtom.cjs","names":[],"sources":["../src/useCreateAtom.ts"],"sourcesContent":["import { useState } from 'react'\nimport { createAtom } from '@tanstack/store'\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 hook mirrors the overloads from\n * {@link createAtom}, but ensures the atom is only created once per mount.\n *\n * @example\n * ```tsx\n * const countAtom = useCreateAtom(0)\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":";;;;AAwBA,SAAgB,cACd,WACA,SAC2B;CAC3B,MAAM,CAAC,kCAAkD;AACvD,MAAI,OAAO,cAAc,WACvB,wCAAkB,WAAuC,QAAQ;AAGnE,yCAAkB,WAAW,QAAQ;GACrC;AAEF,QAAO"}