minh-custom-hooks-release
Version:
My custom hooks for working easier while developing react web app
58 lines (57 loc) • 2.51 kB
TypeScript
import { EnumTaskState } from '../hooks/useTask';
export type GlobalFetchValueType<TValue = any, TRunTask extends (...args: any[]) => void = () => void> = {
data?: TValue;
isLoading: boolean;
error?: string;
refetch: TRunTask;
reset: (...args: any) => void;
cancel: (...args: any) => void;
isSuccess: boolean;
isError: boolean;
isIdle: boolean;
status: EnumTaskState;
};
export declare function createInitGlobalFetchValue<TValue = any, TRunTask extends (...args: any[]) => void = () => void>(data?: TValue, initRunTask?: TRunTask, cancel?: () => void, reset?: () => void): {
data: TValue | undefined;
isLoading: boolean;
error: undefined;
refetch: TRunTask;
reset: () => void;
cancel: () => void;
isSuccess: boolean;
isError: boolean;
isIdle: boolean;
status: EnumTaskState;
};
export default function fetchActionsCreators<TPrefix extends string, TValue extends any, TActions extends Record<string, (...args: [state: GlobalFetchValueType<TValue>, ...any[]]) => GlobalFetchValueType<TValue>>, TRunTask extends (...args: any[]) => void = () => void>(key: TPrefix, initData: GlobalFetchValueType<TValue, TRunTask>, actions?: TActions): {
reducer: (state: GlobalFetchValueType<TValue, TRunTask> | undefined, action: {
type: `${TPrefix}/initFetching` | `${TPrefix}/startFetching` | `${TPrefix}/successFetching` | `${TPrefix}/errorFetching` | `${TPrefix}/cancelFetching` | `${TPrefix}/resetData`;
payload?: any;
}) => GlobalFetchValueType<TValue, TRunTask>;
generateActions: {
initFetching: (initRunTask: TRunTask, cancel: () => void, reset: () => void) => {
type: `${TPrefix}/initFetching`;
payload?: [initRunTask: TRunTask, cancel: () => void, reset: () => void] | undefined;
};
startFetching: () => {
type: `${TPrefix}/startFetching`;
payload?: [] | undefined;
};
successFetching: (data: TValue) => {
type: `${TPrefix}/successFetching`;
payload?: [data: TValue] | undefined;
};
errorFetching: (error: string) => {
type: `${TPrefix}/errorFetching`;
payload?: [error: string] | undefined;
};
cancelFetching: () => {
type: `${TPrefix}/cancelFetching`;
payload?: [] | undefined;
};
resetData: () => {
type: `${TPrefix}/resetData`;
payload?: [] | undefined;
};
};
};