Store Docs
API Reference
Store API Reference
- Store
- ReadonlyStore
- Atom
- AtomOptions
- BaseAtom
- InternalBaseAtom
- InternalReadonlyAtom
- InteropSubscribable
- Readable
- ReadonlyAtom
- StoreActionsApi
- Subscribable
- Subscription
- AnyAtom
- Observer
- Selection
- StoreAction
- StoreActionMap
- StoreActionsFactory
- batch
- createAsyncAtom
- createAtom
- createStore
- flush
- shallow
- toObserver
- createStoreContext
- useCreateAtom
- useCreateStore
- useSelector
- useSetValue
- useAtom
- useStoreActions
- _useStore (experimental)
- useStore (deprecated)
- UseSelectorOptions
AI/LLM: This documentation page is available in plain markdown format at/store/latest/docs/framework/preact/reference/functions/useSelector.md
Store API Reference
useSelector
ts
function useSelector<TSource, TSelected>(
source,
selector?,
options?): TSelected;Defined in: useSelector.ts:129
Selects a slice of state from an atom or store and subscribes the component to that selection.
This is the primary Preact read hook for TanStack Store. Use it when a component only needs part of a source value, or omit the selector to subscribe to the whole value.
Type Parameters#
TSource#
TSource
TSelected#
TSelected = NoInfer<TSource>
Parameters#
source#
SelectionSource<TSource>
selector?#
(snapshot) => TSelected
options?#
UseSelectorOptions<TSelected>
Returns#
TSelected
Examples#
tsx
const count = useSelector(counterStore, (state) => state.count)tsx
const value = useSelector(countAtom)