Skip to content

Commit 8c14d8f

Browse files
authored
refactor: use @rc-component/context (#916)
1 parent 191d82e commit 8c14d8f

18 files changed

+31
-179
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
},
5555
"dependencies": {
5656
"@babel/runtime": "^7.10.1",
57+
"@rc-component/context": "^1.0.0",
5758
"classnames": "^2.2.5",
5859
"rc-resize-observer": "^1.1.0",
5960
"rc-util": "^5.22.5",

src/Body/BodyRow.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
import Cell from '../Cell';
44
import BodyContext from '../context/BodyContext';
55
import TableContext from '../context/TableContext';
6-
import { useContextSelector } from '../ContextSelector';
6+
import { useContext } from '@rc-component/context';
77
import type {
88
ColumnType,
99
CustomizeComponent,
@@ -52,7 +52,7 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
5252
scopeCellComponent,
5353
childrenColumnName,
5454
} = props;
55-
const { prefixCls, fixedInfoList } = useContextSelector(TableContext, [
55+
const { prefixCls, fixedInfoList } = useContext(TableContext, [
5656
'prefixCls',
5757
'fixedInfoList',
5858
]);
@@ -67,7 +67,7 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
6767
expandIcon,
6868
expandedRowRender,
6969
expandIconColumnIndex,
70-
} = useContextSelector(BodyContext, [
70+
} = useContext(BodyContext, [
7171
'flattenColumns',
7272
'expandableType',
7373
'expandRowByClick',

src/Body/ExpandedRow.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import Cell from '../Cell';
33
import ExpandedRowContext from '../context/ExpandedRowContext';
44
import TableContext from '../context/TableContext';
5-
import { useContextSelector } from '../ContextSelector';
5+
import { useContext } from '@rc-component/context';
66
import type { CustomizeComponent } from '../interface';
77

88
export interface ExpandedRowProps {
@@ -26,8 +26,8 @@ function ExpandedRow({
2626
colSpan,
2727
isEmpty,
2828
}: ExpandedRowProps) {
29-
const scrollbarSize = useContextSelector(TableContext, 'scrollbarSize');
30-
const { fixHeader, fixColumn, componentWidth, horizonScroll } = useContextSelector(
29+
const scrollbarSize = useContext(TableContext, 'scrollbarSize');
30+
const { fixHeader, fixColumn, componentWidth, horizonScroll } = useContext(
3131
ExpandedRowContext,
3232
['fixHeader', 'fixColumn', 'componentWidth', 'horizonScroll'],
3333
);

src/Body/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { PerfRecord } from '../context/PerfContext';
55
import PerfContext from '../context/PerfContext';
66
import ResizeContext from '../context/ResizeContext';
77
import TableContext from '../context/TableContext';
8-
import { useContextSelector } from '../ContextSelector';
8+
import { useContext } from '@rc-component/context';
99
import useFlattenRecords from '../hooks/useFlattenRecords';
1010
import type { GetComponentProps, GetRowKey, Key } from '../interface';
1111
import { getColumnsKey } from '../utils/valueUtil';
@@ -34,12 +34,12 @@ function Body<RecordType>({
3434
emptyNode,
3535
childrenColumnName,
3636
}: BodyProps<RecordType>) {
37-
const onColumnResize = useContextSelector(ResizeContext, 'onColumnResize');
38-
const { prefixCls, getComponent } = useContextSelector(TableContext, [
37+
const onColumnResize = useContext(ResizeContext, 'onColumnResize');
38+
const { prefixCls, getComponent } = useContext(TableContext, [
3939
'prefixCls',
4040
'getComponent',
4141
]);
42-
const flattenColumns = useContextSelector(BodyContext, 'flattenColumns');
42+
const flattenColumns = useContext(BodyContext, 'flattenColumns');
4343

4444
const flattenData: { record: RecordType; indent: number; index: number }[] =
4545
useFlattenRecords<RecordType>(data, childrenColumnName, expandedKeys, getRowKey);

src/Cell/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { HoverContextProps } from '../context/HoverContext';
88
import HoverContext from '../context/HoverContext';
99
import PerfContext from '../context/PerfContext';
1010
import StickyContext from '../context/StickyContext';
11-
import { useContextSelector } from '../ContextSelector';
11+
import { useContext } from '@rc-component/context';
1212
import type {
1313
AlignType,
1414
CellEllipsisType,
@@ -146,7 +146,7 @@ function Cell<RecordType extends DefaultRecordType>(
146146

147147
const perfRecord = React.useContext(PerfContext);
148148
const supportSticky = React.useContext(StickyContext);
149-
const allColumnsFixedLeft = useContextSelector(BodyContext, 'allColumnsFixedLeft');
149+
const allColumnsFixedLeft = useContext(BodyContext, 'allColumnsFixedLeft');
150150

151151
// ==================== Child Node ====================
152152
const [childNode, legacyCellProps] = React.useMemo<
@@ -342,7 +342,7 @@ const WrappedCell = React.forwardRef((props: CellProps<any>, ref: React.Ref<any>
342342
const mergedColSpan = colSpan ?? cellColSpan;
343343
const mergedRowSpan = rowSpan ?? cellRowSpan;
344344

345-
const { onHover, hovering } = useContextSelector(HoverContext, cxt => {
345+
const { onHover, hovering } = useContext(HoverContext, cxt => {
346346
const isHovering = inHoverRange(index, mergedRowSpan || 1, cxt?.startRow, cxt?.endRow);
347347

348348
return {

src/ContextSelector/index.tsx

Lines changed: 0 additions & 113 deletions
This file was deleted.

src/FixedHolder/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as React from 'react';
44
import { useMemo } from 'react';
55
import ColGroup from '../ColGroup';
66
import TableContext from '../context/TableContext';
7-
import { useContextSelector } from '../ContextSelector';
7+
import { useContext } from '@rc-component/context';
88
import type { HeaderProps } from '../Header/Header';
99
import type { ColumnsType, ColumnType } from '../interface';
1010

@@ -60,7 +60,7 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<unknown>>(
6060
},
6161
ref,
6262
) => {
63-
const { prefixCls, scrollbarSize, isSticky } = useContextSelector(TableContext, [
63+
const { prefixCls, scrollbarSize, isSticky } = useContext(TableContext, [
6464
'prefixCls',
6565
'scrollbarSize',
6666
'isSticky',

src/Footer/Cell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import Cell from '../Cell';
33
import TableContext from '../context/TableContext';
4-
import { useContextSelector } from '../ContextSelector';
4+
import { useContext } from '@rc-component/context';
55
import type { AlignType } from '../interface';
66
import { getCellFixedInfo } from '../utils/fixUtil';
77
import SummaryContext from './SummaryContext';
@@ -23,7 +23,7 @@ export default function SummaryCell({
2323
rowSpan,
2424
align,
2525
}: SummaryCellProps) {
26-
const { prefixCls, direction } = useContextSelector(TableContext, ['prefixCls', 'direction']);
26+
const { prefixCls, direction } = useContext(TableContext, ['prefixCls', 'direction']);
2727
const { scrollColumnIndex, stickyOffsets, flattenColumns } = React.useContext(SummaryContext);
2828
const lastIndex = index + colSpan - 1;
2929
const mergedColSpan = lastIndex + 1 === scrollColumnIndex ? colSpan + 1 : colSpan;

src/Footer/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import TableContext from '../context/TableContext';
3-
import { useContextSelector } from '../ContextSelector';
3+
import { useContext } from '@rc-component/context';
44
import type { ColumnType, StickyOffsets } from '../interface';
55
import Summary from './Summary';
66
import SummaryContext from './SummaryContext';
@@ -14,7 +14,7 @@ export interface FooterProps<RecordType> {
1414
}
1515

1616
function Footer<RecordType>({ children, stickyOffsets, flattenColumns }: FooterProps<RecordType>) {
17-
const prefixCls = useContextSelector(TableContext, 'prefixCls');
17+
const prefixCls = useContext(TableContext, 'prefixCls');
1818

1919
const lastColumnIndex = flattenColumns.length - 1;
2020
const scrollColumn = flattenColumns[lastColumnIndex];

src/Header/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import TableContext from '../context/TableContext';
3-
import { useContextSelector } from '../ContextSelector';
3+
import { useContext } from '@rc-component/context';
44
import type {
55
CellType,
66
ColumnGroupType,
@@ -95,7 +95,7 @@ function Header<RecordType>({
9595
flattenColumns,
9696
onHeaderRow,
9797
}: HeaderProps<RecordType>): React.ReactElement {
98-
const { prefixCls, getComponent } = useContextSelector(TableContext, [
98+
const { prefixCls, getComponent } = useContext(TableContext, [
9999
'prefixCls',
100100
'getComponent',
101101
]);

0 commit comments

Comments
 (0)