type: strong type (#37481)

pull/37499/head
lijianan 2 years ago committed by GitHub
parent 370c37cb30
commit 1922ad3512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,17 +6,18 @@ export function isFragment(child: React.ReactElement): boolean {
return child && child.type === React.Fragment;
}
type AnyObject = Record<any, any>;
type AnyObject = Record<PropertyKey, any>;
type RenderProps = undefined | AnyObject | ((originProps: AnyObject) => AnyObject | undefined);
type RenderProps = AnyObject | ((originProps: AnyObject) => AnyObject | void);
export function replaceElement(
element: React.ReactNode,
replacement: React.ReactNode,
props: RenderProps,
props?: RenderProps,
): React.ReactNode {
if (!isValidElement(element)) return replacement;
if (!isValidElement(element)) {
return replacement;
}
return React.cloneElement(
element,
typeof props === 'function' ? props(element.props || {}) : props,

Loading…
Cancel
Save