Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lbg-hooks

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lbg-hooks

LBG reacthooks集合

  • 0.0.5
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

LBG Hooks

开发

编译发包

npm run build //目前是使用tsc简单的编译源文件,之后会优化为rollup构建,以支持treeShaking等优化
npm publish

使用文档

useAntdTable

@desc 处理antd的table分页场景

import { FC } from 'react';
import { Table } from 'antd'
import { useAntdTable } from 'lbg-hooks';
import { PageParams } from 'lbg-hooks/lib/useAntdTable';//用来修饰页码的TS类型
const HookDemo:FC<{}> = ()=>{

    const [queryParams, setQueryParams] = useState<Partial<ListQueryParams>>({});

     // 列表请求
    const requestTableData = async (pageParams: PageParams) => {
        const res:any = await get(GET_LIST, {
            ...queryParams,
            ...pageParams,
        }, true);

        return {
            total: res?.count || 0,
            data: res?.data || [],
        };
    };

    const { tableProps, resetTable, reloadTable } = useAntdTable(requestTableData, [
        queryParams,
    ]);

    return   <Table rowKey='id' columns={columns} {...tableProps} />
}
   
参数解释
request请求方法。 需返回一个结果包含总页数及列表数据的Promise实例
deps表格重置的依赖项。需要依赖一个状态,任意依赖项发生变化,重置页码为1,自动调用request方法,设计灵感来源于react的useEffect,区别是react是依赖变化运行渲染副作用,这里是重置表格数据。
options自定义选项 {isInit:true;//是否在初始化时候默认触发一次请求 默认为true}

除了以上依靠deps参数实现的自动模式,也另外导出了一些hook内部的实用方法,以灵活应对更多场景:

interface Result<RecordType> {
  tableProps: TableProps<RecordType>; // 表格属性
  resetTable: () => void; // 手动重置表格 页码会重置为第一页
  reloadTable: () => void; // 手动刷新当前页的表格数据
}

Keywords

FAQs

Package last updated on 28 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc