Download node_modules/@tanstack/react-store/src/useCreateStore.ts from sitcod3/modul-s: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/sitcod3/modul-s/resolve/c06e4783a2be21cd7ca9fedf1ede4d4f0156ba3a/node_modules/%40tanstack/react-store/src/useCreateStore.ts
- Command line
-
hf download hf://spaces/sitcod3/modul-s@c06e4783a2be21cd7ca9fedf1ede4d4f0156ba3a/node_modules/@tanstack/react-store/src/useCreateStore.ts
-
curl -L -o useCreateStore.ts https://huggingface.co/spaces/sitcod3/modul-s/resolve/c06e4783a2be21cd7ca9fedf1ede4d4f0156ba3a/node_modules/%40tanstack/react-store/src/useCreateStore.ts
1.55 kB
| import { useState } from 'react' | |
| import { createStore } from '@tanstack/store' | |
| import type { | |
| ReadonlyStore, | |
| Store, | |
| StoreActionMap, | |
| StoreActionsFactory, | |
| } from '@tanstack/store' | |
| type NonFunction<T> = T extends (...args: Array<any>) => any ? never : T | |
| /** | |
| * Creates a stable store instance for the lifetime of the component. | |
| * | |
| * Pass an initial value to create a writable store, or a getter function to | |
| * create a readonly derived store. This hook mirrors the overloads from | |
| * {@link createStore}, but ensures the store is only created once per mount. | |
| * | |
| * @example | |
| * ```tsx | |
| * const counterStore = useCreateStore({ count: 0 }) | |
| * ``` | |
| */ | |
| export function useCreateStore<T>( | |
| getValue: (prev?: NoInfer<T>) => T, | |
| ): ReadonlyStore<T> | |
| export function useCreateStore<T>(initialValue: T): Store<T> | |
| export function useCreateStore<T, TActions extends StoreActionMap>( | |
| initialValue: NonFunction<T>, | |
| actions: StoreActionsFactory<T, TActions>, | |
| ): Store<T, TActions> | |
| export function useCreateStore<T, TActions extends StoreActionMap>( | |
| valueOrFn: T | ((prev?: T) => T), | |
| actions?: StoreActionsFactory<T, TActions>, | |
| ): Store<T, TActions> | Store<T> | ReadonlyStore<T> { | |
| const [store] = useState<Store<T, TActions> | Store<T> | ReadonlyStore<T>>( | |
| () => { | |
| if (typeof valueOrFn === 'function') { | |
| return createStore(valueOrFn as (prev?: NoInfer<T>) => T) | |
| } | |
| if (actions) { | |
| return createStore(valueOrFn as NonFunction<T>, actions) | |
| } | |
| return createStore(valueOrFn) | |
| }, | |
| ) | |
| return store | |
| } | |