refactor: Input.Group use context hook (#34361)

This commit is contained in:
MadCcc 2022-03-08 15:09:02 +08:00 committed by GitHub
parent 8fe8df777e
commit 33ddc539df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
import * as React from 'react';
import { useContext } from 'react';
import classNames from 'classnames';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import { ConfigContext } from '../config-provider';
export interface GroupProps {
className?: string;
@ -15,9 +16,8 @@ export interface GroupProps {
compact?: boolean;
}
const Group: React.FC<GroupProps> = props => (
<ConfigConsumer>
{({ getPrefixCls, direction }: ConfigConsumerProps) => {
const Group: React.FC<GroupProps> = props => {
const { getPrefixCls, direction } = useContext(ConfigContext);
const { prefixCls: customizePrefixCls, className = '' } = props;
const prefixCls = getPrefixCls('input-group', customizePrefixCls);
const cls = classNames(
@ -30,6 +30,7 @@ const Group: React.FC<GroupProps> = props => (
},
className,
);
return (
<span
className={cls}
@ -42,8 +43,6 @@ const Group: React.FC<GroupProps> = props => (
{props.children}
</span>
);
}}
</ConfigConsumer>
);
};
export default Group;