ant-design/components/_util/reactNode.ts
二货机器人 2afab58ac8
chore: small bundle size follow up (#24164)
* update config

* replace react function

* fix alert
2020-05-14 20:54:49 +08:00

18 lines
518 B
TypeScript

import * as React from 'react';
export const isValidElement = React.isValidElement;
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;
}