UNPKG

dolab

Version:

Lightweight and fast React hooks library for fetching and managing data with Zustand state management. Ideal for scalable and modern React applications.

44 lines (35 loc) 1.18 kB
// src/dolab/dolab.d.ts export type Id = string; export type IData<T> = Record<Id, T>; export type ILoading = Record<Id, boolean>; export type IExpiry = Record<Id, number | null>; export type IRefetch = Record<Id, string | undefined>; export type ISetDolabData<T> = (id: Id, data: T, lifeTime?: number) => void; export type SetDolabData<T> = (data: T) => void; export type IDolabStore<T> = { data: IData<T>; setData: ISetDolabData<T>; loading: ILoading; setLoading: (id: Id, newState: boolean) => void; expiry: IExpiry; cleanupExpiredData: () => void; refetch: IRefetch; setRefetch: (id: Id) => void; }; export type IDolab<T> = { id: string; fetch: (setData: SetDolabData<T>, ...args: any) => Promise<void>; lifeTime?: number; deps?: any[]; }; export type IDolabData<T> = { id: Id; }; export type IUseDolabData<T> = { data: T | undefined; loading: boolean; triggerRefetch: () => void; }; // Function declarations (if you don’t already declare them elsewhere) export function useDolab<T>(props: IDolab<T>): IUseDolabData<T>; export function useDolabData<T>(props: IDolabData<T>): IUseDolabData<T>;