Skip to content

Commit ccbec33

Browse files
authored
type: remove redundant useContext (ant-design#39955)
* type: remove redundant useContext * add type
1 parent b44b4e7 commit ccbec33

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

components/cascader/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const Cascader = React.forwardRef((props: CascaderProps<any>, ref: React.Ref<Cas
148148
...rest
149149
} = props;
150150

151-
const restProps = omit(rest, ['suffixIcon' as any]);
151+
const restProps = omit(rest, ['suffixIcon']);
152152

153153
const {
154154
getPopupContainer: getContextPopupContainer,

components/table/Table.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { TableProps as RcTableProps } from 'rc-table/lib/Table';
55
import { INTERNAL_HOOKS } from 'rc-table/lib/Table';
66
import omit from 'rc-util/lib/omit';
77
import * as React from 'react';
8+
import type { ConfigConsumerProps } from '../config-provider/context';
89
import { ConfigContext } from '../config-provider/context';
910
import defaultRenderEmpty from '../config-provider/defaultRenderEmpty';
1011
import type { SizeType } from '../config-provider/SizeContext';
@@ -169,19 +170,21 @@ function InternalTable<RecordType extends object = any>(
169170
);
170171
}, [baseColumns, screens]);
171172

172-
const tableProps = omit(props, ['className', 'style', 'columns']) as TableProps<RecordType>;
173+
const tableProps: TableProps<RecordType> = omit(props, ['className', 'style', 'columns']);
174+
175+
const size = React.useContext<SizeType>(SizeContext);
173176

174-
const size = React.useContext(SizeContext);
175177
const {
176178
locale: contextLocale = defaultLocale,
177-
renderEmpty,
178179
direction,
179-
} = React.useContext(ConfigContext);
180+
renderEmpty,
181+
getPrefixCls,
182+
} = React.useContext<ConfigConsumerProps>(ConfigContext);
183+
180184
const mergedSize = customizeSize || size;
181-
const tableLocale = { ...contextLocale.Table, ...locale } as TableLocale;
185+
const tableLocale: TableLocale = { ...contextLocale.Table, ...locale };
182186
const rawData: readonly RecordType[] = dataSource || EMPTY_LIST;
183187

184-
const { getPrefixCls } = React.useContext(ConfigContext);
185188
const prefixCls = getPrefixCls('table', customizePrefixCls);
186189
const dropdownPrefixCls = getPrefixCls('dropdown', customizeDropdownPrefixCls);
187190

0 commit comments

Comments
 (0)