You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

22 lines
603 B

import React from 'react';
import type { SizeType } from '../SizeContext';
import SizeContext from '../SizeContext';
const useSize = <T>(customSize?: T | ((ctxSize: SizeType) => T)): T => {
const size = React.useContext<SizeType>(SizeContext);
const mergedSize = React.useMemo<T>(() => {
if (!customSize) {
return size as T;
}
if (typeof customSize === 'string') {
return customSize ?? size;
}
if (customSize instanceof Function) {
return customSize(size);
}
return size as T;
}, [customSize, size]);
return mergedSize;
};
export default useSize;