modul-s / node_modules /@tanstack /react-store /dist /useCreateStore.cjs.map
sitcod3's picture
Upload folder using huggingface_hub (part 11)
5144199 verified
Raw History Blame
1.89 kB
{"version":3,"file":"useCreateStore.cjs","names":[],"sources":["../src/useCreateStore.ts"],"sourcesContent":["import { useState } from 'react'\nimport { createStore } from '@tanstack/store'\nimport type {\n ReadonlyStore,\n Store,\n StoreActionMap,\n StoreActionsFactory,\n} from '@tanstack/store'\n\ntype NonFunction<T> = T extends (...args: Array<any>) => any ? never : T\n\n/**\n * Creates a stable store instance for the lifetime of the component.\n *\n * Pass an initial value to create a writable store, or a getter function to\n * create a readonly derived store. This hook mirrors the overloads from\n * {@link createStore}, but ensures the store is only created once per mount.\n *\n * @example\n * ```tsx\n * const counterStore = useCreateStore({ count: 0 })\n * ```\n */\nexport function useCreateStore<T>(\n getValue: (prev?: NoInfer<T>) => T,\n): ReadonlyStore<T>\nexport function useCreateStore<T>(initialValue: T): Store<T>\nexport function useCreateStore<T, TActions extends StoreActionMap>(\n initialValue: NonFunction<T>,\n actions: StoreActionsFactory<T, TActions>,\n): Store<T, TActions>\nexport function useCreateStore<T, TActions extends StoreActionMap>(\n valueOrFn: T | ((prev?: T) => T),\n actions?: StoreActionsFactory<T, TActions>,\n): Store<T, TActions> | Store<T> | ReadonlyStore<T> {\n const [store] = useState<Store<T, TActions> | Store<T> | ReadonlyStore<T>>(\n () => {\n if (typeof valueOrFn === 'function') {\n return createStore(valueOrFn as (prev?: NoInfer<T>) => T)\n }\n\n if (actions) {\n return createStore(valueOrFn as NonFunction<T>, actions)\n }\n\n return createStore(valueOrFn)\n },\n )\n\n return store\n}\n"],"mappings":";;;;AA+BA,SAAgB,eACd,WACA,SACkD;CAClD,MAAM,CAAC,mCACC;AACJ,MAAI,OAAO,cAAc,WACvB,yCAAmB,UAAsC;AAG3D,MAAI,QACF,yCAAmB,WAA6B,QAAQ;AAG1D,0CAAmB,UAAU;GAEhC;AAED,QAAO"}