2019-04-24 12:21:02 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
|
2020-05-14 20:54:49 +08:00
|
|
|
export const isValidElement = React.isValidElement;
|
2019-04-24 12:21:02 +08:00
|
|
|
|
2020-05-14 20:54:49 +08:00
|
|
|
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;
|
2019-05-07 14:57:32 +08:00
|
|
|
}
|