zustand-ards
Version:
A library of simple opinionated utilities for zustand. zustand-ards are typesafe and designed to be easily added to an existing codebase to improve the experience of developing with zustand.
18 lines (15 loc) • 1 kB
TypeScript
import { UseBoundStoreWithEqualityFn } from 'zustand/traditional';
import { ReadonlyStoreApi, ExtractState, PartObjFromArrOfKeys } from './types.js';
import 'zustand';
/**
* Extends the UseBoundStoreWithEqualityFn type to include the function overload for an array selector.
*/
type UseBoundStoreWithArraySelector<S extends ReadonlyStoreApi<unknown>> = {
<U, A extends (keyof ExtractState<S>)[]>(selector: A, equals?: (a: PartObjFromArrOfKeys<ExtractState<S>, A>, b: PartObjFromArrOfKeys<ExtractState<S>, A>) => boolean): PartObjFromArrOfKeys<ExtractState<S>, A>;
} & UseBoundStoreWithEqualityFn<S>;
/**
* This enhances the traditionalstore hook by adding another style of selector: an array of keys from the provided store.
* It elimnates the need to use multiple hooks or a complex selector function.
*/
declare const withArraySelector: <T>(storeHook: UseBoundStoreWithEqualityFn<ReadonlyStoreApi<T>>) => UseBoundStoreWithArraySelector<ReadonlyStoreApi<T>>;
export { withArraySelector };