zustand-tracked
Version:
A small library that allows all your zustand store selectors to be tracked, optimizing computations and rerenders.
35 lines (22 loc) • 1.31 kB
TypeScript
import { create } from 'zustand';
import { createWithEqualityFn } from 'zustand/traditional';
import { StateCreator } from 'zustand';
import { StoreMutatorIdentifier } from 'zustand';
import { useStore } from 'zustand';
import { useStoreWithEqualityFn } from 'zustand/traditional';
declare type Compute<T> = (state: T) => Partial<T>;
declare type Computed = <T extends object>(
/**
* The function that computes the derived state.
*/
compute: Compute<T>) => <Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = []>(creator: StateCreator<T, [...Mps], Mcs>) => StateCreator<T, Mps, [...Mcs]>;
export declare const createTracked: UseBoundStoreWithTracked;
export declare const createTrackedComputer: Computed;
export declare const createTrackedWithEqualityFn: UseBoundStoreWithTrackedEqualityFn;
declare type UseBoundStoreWithTracked = typeof create;
declare type UseBoundStoreWithTrackedEqualityFn = typeof createWithEqualityFn;
declare type UseStoreWithTracked = typeof useStore;
declare type UseStoreWithTrackedEqualityFn = typeof useStoreWithEqualityFn;
export declare const useTrackedStore: UseStoreWithTracked;
export declare const useTrackedStoreWithEqualityFn: UseStoreWithTrackedEqualityFn;
export { }