Download node_modules/@tanstack/react-store/dist/useSelector.cjs from sitcod3/modul-s: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/sitcod3/modul-s/resolve/c06e4783a2be21cd7ca9fedf1ede4d4f0156ba3a/node_modules/%40tanstack/react-store/dist/useSelector.cjs
- Command line
-
hf download hf://spaces/sitcod3/modul-s@c06e4783a2be21cd7ca9fedf1ede4d4f0156ba3a/node_modules/@tanstack/react-store/dist/useSelector.cjs
-
curl -L -o useSelector.cjs https://huggingface.co/spaces/sitcod3/modul-s/resolve/c06e4783a2be21cd7ca9fedf1ede4d4f0156ba3a/node_modules/%40tanstack/react-store/dist/useSelector.cjs
1.32 kB
| let react = require("react"); | |
| let use_sync_external_store_shim_with_selector = require("use-sync-external-store/shim/with-selector"); | |
| //#region src/useSelector.ts | |
| function defaultCompare(a, b) { | |
| return a === b; | |
| } | |
| /** | |
| * Selects a slice of state from an atom or store and subscribes the component | |
| * to that selection. | |
| * | |
| * This is the primary React read hook for TanStack Store. It works with any | |
| * source that exposes `get()` and `subscribe()`, including atoms, readonly | |
| * atoms, stores, and readonly stores. | |
| * | |
| * Omit the selector to subscribe to the whole value. | |
| * | |
| * @example | |
| * ```tsx | |
| * const count = useSelector(counterStore, (state) => state.count) | |
| * ``` | |
| * | |
| * @example | |
| * ```tsx | |
| * const value = useSelector(countAtom) | |
| * ``` | |
| */ | |
| function useSelector(source, selector = (s) => s, options) { | |
| const compare = options?.compare ?? defaultCompare; | |
| const subscribe = (0, react.useCallback)((handleStoreChange) => { | |
| const { unsubscribe } = source.subscribe(handleStoreChange); | |
| return unsubscribe; | |
| }, [source]); | |
| const getSnapshot = (0, react.useCallback)(() => source.get(), [source]); | |
| return (0, use_sync_external_store_shim_with_selector.useSyncExternalStoreWithSelector)(subscribe, getSnapshot, getSnapshot, selector, compare); | |
| } | |
| //#endregion | |
| exports.useSelector = useSelector; | |
| //# sourceMappingURL=useSelector.cjs.map |