refactor: resolve useSize circular reference (#42810)

This commit is contained in:
Zack Chang 2023-06-25 10:14:41 +08:00 committed by GitHub
parent 36a5392f99
commit 5827f9ddef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,4 @@
import * as React from 'react';
import useSize from './hooks/useSize';
export type SizeType = 'small' | 'middle' | 'large' | undefined;
@ -11,8 +10,8 @@ export interface SizeContextProps {
}
export const SizeContextProvider: React.FC<SizeContextProps> = ({ children, size }) => {
const mergedSize = useSize(size);
return <SizeContext.Provider value={mergedSize}>{children}</SizeContext.Provider>;
const originSize = React.useContext<SizeType>(SizeContext);
return <SizeContext.Provider value={size || originSize}>{children}</SizeContext.Provider>;
};
export default SizeContext;