mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-13 07:39:10 +08:00
637aa09bc5
* 💄 fix lint * 💄 fix lint
18 lines
507 B
TypeScript
18 lines
507 B
TypeScript
import * as React from 'react';
|
|
|
|
export const { isValidElement } = React;
|
|
|
|
export function replaceElement(
|
|
element: React.ReactNode,
|
|
replacement: React.ReactNode,
|
|
props: any,
|
|
): React.ReactNode {
|
|
if (!isValidElement(element)) return replacement;
|
|
|
|
return React.cloneElement(element, typeof props === 'function' ? props() : props);
|
|
}
|
|
|
|
export function cloneElement(element: React.ReactNode, props?: any): React.ReactElement {
|
|
return replaceElement(element, element, props) as React.ReactElement;
|
|
}
|