SemmyWong 12f58effad
refactor: code splitting of the table component (#121)
* refactor: 表格拆分模块化

* refactor: 表格拆分模块化

* refactor: code splitting of the table component (#120)

* missing TableIndex

* refactor: 表格拆分模块化

* code format

Co-authored-by: chenos <chenlinxh@gmail.com>
2021-12-02 22:56:16 +08:00

17 lines
552 B
TypeScript

import { useContext } from 'react';
import { useTable } from './useTable';
import { TableRowContext } from '../context';
export const useTableIndex = () => {
const { pagination, props } = useTable();
const ctx = useContext(TableRowContext);
const { pageSize, page = 1 } = pagination;
console.log({ pageSize, page }, ctx.index);
return ctx.index + (page - 1) * pageSize;
if (pagination && !props.clientSidePagination) {
const { pageSize, page = 1 } = pagination;
return ctx.index + (page - 1) * pageSize;
}
return ctx.index;
};