From 669e58c380449e5552fb76e90e98dba3b5f4d43b Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Tue, 14 Mar 2023 10:54:46 +0800 Subject: [PATCH] refactor: use React.useContext replace ConfigConsumer (#41184) * chore: use React.useContext replace ConfigConsumer * fix --- components/anchor/AnchorLink.tsx | 55 ++++++++++++++++---------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/components/anchor/AnchorLink.tsx b/components/anchor/AnchorLink.tsx index 421b344368..3743e85971 100644 --- a/components/anchor/AnchorLink.tsx +++ b/components/anchor/AnchorLink.tsx @@ -1,7 +1,6 @@ import classNames from 'classnames'; import * as React from 'react'; -import type { ConfigConsumerProps } from '../config-provider'; -import { ConfigConsumer } from '../config-provider'; +import { ConfigContext } from '../config-provider'; import warning from '../_util/warning'; import type { AntAnchor } from './Anchor'; import AnchorContext from './context'; @@ -46,33 +45,33 @@ const AnchorLink: React.FC = (props) => { ); } + const { getPrefixCls } = React.useContext(ConfigContext); + + const prefixCls = getPrefixCls('anchor', customizePrefixCls); + + const active = activeLink === href; + + const wrapperClassName = classNames(`${prefixCls}-link`, className, { + [`${prefixCls}-link-active`]: active, + }); + + const titleClassName = classNames(`${prefixCls}-link-title`, { + [`${prefixCls}-link-title-active`]: active, + }); + return ( - - {({ getPrefixCls }: ConfigConsumerProps) => { - const prefixCls = getPrefixCls('anchor', customizePrefixCls); - const active = activeLink === href; - const wrapperClassName = classNames(`${prefixCls}-link`, className, { - [`${prefixCls}-link-active`]: active, - }); - const titleClassName = classNames(`${prefixCls}-link-title`, { - [`${prefixCls}-link-title-active`]: active, - }); - return ( -
- - {title} - - {direction !== 'horizontal' ? children : null} -
- ); - }} -
+
+ + {title} + + {direction !== 'horizontal' ? children : null} +
); };