@gdjiami/hooks
Version:
react hooks for mygzb.com
36 lines (35 loc) • 866 B
TypeScript
export interface UsePollOptions<T> {
/**
* determinate should continue poll
* @param arg poller return value
*/
condition: (arg?: T, error?: Error) => Promise<boolean>;
/**
* poll action
*/
poller: () => Promise<T>;
onError?: (err: Error) => void;
/**
* poll duration. default is 5000
*/
duration?: number;
/**
* ignore poller's error. default is false
*/
ignoreError?: boolean;
/**
* watching arguments. when these arguments change, usePoll will recheck condition
*/
args?: any[];
/**
* poll immediately, default is false
*/
immediately?: boolean;
}
/**
* 实现页面轮询机制
*/
export default function usePoll<T = any>(options: UsePollOptions<T>): {
polling: boolean;
error: Error | undefined;
};