UNPKG

taro-hooks

Version:
23 lines 796 B
import { startPullDownRefresh, stopPullDownRefresh } from '@tarojs/taro'; import { useRef } from '@taro-hooks/core'; import { isNumber } from '@taro-hooks/shared'; import usePromise from '../usePromise'; function useManualPullDownRefresh() { var timer = useRef(); var startAsync = usePromise(startPullDownRefresh); var stop = usePromise(stopPullDownRefresh); var start = function start(duration) { timer.current && clearTimeout(timer.current); return startAsync().then(function (res) { if (isNumber(duration) && duration) { timer.current = setTimeout(function () { stop(); timer.current && clearTimeout(timer.current); }, duration); } return res; }); }; return [start, stop]; } export default useManualPullDownRefresh;