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

zyd-react-hooks

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zyd-react-hooks

LBG reacthooks集合

  • 0.0.3
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

react Hooks

安装

编译发包

npm i zyd-react-hooks

使用文档

useAntdTable

用途:

处理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 = 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表格重置的依赖项。任意依赖项发生变化,会重置请求第一页的数据,通常是依赖一个queryState(查询表单的值状态)。 设计灵感来源于react的useEffect,区别是在react中依赖项变化是重新运行渲染副作用,这里是重置表格数据。
options自定义选项 {isInit:true;//是否在组件首次初始化时候就加载列表,默认为true}

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

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

Keywords

FAQs

Package last updated on 29 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