@szmg-fe/hooks
v0.0.56
Published
> 封装了常用的一些hook
Downloads
3
Readme
Hooks
封装了常用的一些hook
Usage
usePagination
Task翻页器
import usePagination from '@szmg-fe/hooks/usePagination';
const axiosList = params => new Task((rej, res) => {
setTimeout(() => {
res({
content: [1,2,3],
total: 20
});
})
})
// 接收一个http task
// const { initPage = 1, initSize = 10, params = {} } = initConfig || {}; 默认参数
const {list, getList, use, ifDone, initList} = usePagination(axiosList);
list // 所有的请求数据
getList // 每次都会执行翻页请求
use // 注入中间件
ifDone // 是否翻页完成
initList // 将会重新开始请求
useCallback
react hook - useCallback
import {rememberFunction} from 'funba/useCallback';
rememberFunction === useCallback(f, []);
useEffect
react hook - useEffect
import {afterFinishRender} from 'funba/useEffect';
afterFinishRender === useEffect(f, []);
useRefCallback
react hook - useRef+useCallback
export default function useRefCallback<T extends (...args: any[]) => any>(callback: T) {
const callbackRef = useRef(callback);
callbackRef.current = callback;
return useCallback((...args: any[]) => callbackRef.current(...args), []) as T;
}