mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-17 19:00:15 +08:00
17 lines
483 B
TypeScript
17 lines
483 B
TypeScript
|
import React from 'react';
|
||
|
import type { SizeType } from '../../config-provider/SizeContext';
|
||
|
import SizeContext from '../../config-provider/SizeContext';
|
||
|
|
||
|
const useSize = <T extends string>(customizeSize?: T) => {
|
||
|
const size = React.useContext<SizeType>(SizeContext);
|
||
|
const mergeSize = React.useMemo<T>(() => {
|
||
|
if (!customizeSize) {
|
||
|
return size as T;
|
||
|
}
|
||
|
return customizeSize ?? size;
|
||
|
}, [customizeSize, size]);
|
||
|
return mergeSize;
|
||
|
};
|
||
|
|
||
|
export default useSize;
|