mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { AnyStore, InferStoreState } from "../../core/store.js";
|
|
import { Comparator, Selector } from "../../core/shallow-equal.js";
|
|
import "./use-selector.js";
|
|
//#region src/react/hooks/use-store.d.ts
|
|
/**
|
|
* Access store state and actions.
|
|
*
|
|
* Without selector: Returns the store, does NOT subscribe to changes.
|
|
* With selector: Returns selected state, re-renders when selected state changes (shallowEqual).
|
|
*
|
|
* @example
|
|
* ```tsx
|
|
* // Store access (no subscription) - access actions, subscribe without re-render
|
|
* function Controls() {
|
|
* const { setVolume } = useStore(store);
|
|
* }
|
|
*
|
|
* // Selector-based subscription - re-renders when paused changes
|
|
* function PlayButton() {
|
|
* const paused = useStore(store, (s) => s.paused);
|
|
* return <button>{paused ? 'Play' : 'Pause'}</button>;
|
|
* }
|
|
* ```
|
|
*/
|
|
/** @label Without Selector */
|
|
declare function useStore<S extends AnyStore>(store: S): S;
|
|
/**
|
|
* Select a value from the store. Re-renders when the selected value changes (shallowEqual).
|
|
*
|
|
* @label With Selector
|
|
* @param selector - Derives a value from the store state.
|
|
* @param isEqual - Custom equality function. Defaults to `shallowEqual`.
|
|
*/
|
|
declare function useStore<S extends AnyStore, R>(store: S, selector: Selector<InferStoreState<S>, R>, isEqual?: Comparator<R>): R;
|
|
declare namespace useStore {
|
|
type Result<S extends AnyStore> = S;
|
|
}
|
|
//#endregion
|
|
export { useStore };
|
|
//# sourceMappingURL=use-store.d.ts.map
|