@szmg-fe/hooks
TypeScript icon, indicating that this package has built-in type declarations

0.0.56 • Public • Published

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;
  }

Readme

Keywords

none

Package Sidebar

Install

npm i @szmg-fe/hooks

Weekly Downloads

8

Version

0.0.56

License

none

Unpacked Size

56.9 kB

Total Files

27

Last publish

Collaborators

  • lemonzhang