Download ant-design/components/_util/reactNode.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 769 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/ant-design/components/_util/reactNode.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/ant-design/components/_util/reactNode.ts
-
curl -L -o reactNode.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/ant-design/components/_util/reactNode.ts
769 Bytes
| import React from 'react'; | |
| import type { AnyObject } from './type'; | |
| export function isFragment(child: any): boolean { | |
| return child && React.isValidElement(child) && child.type === React.Fragment; | |
| } | |
| type RenderProps = AnyObject | ((originProps: AnyObject) => AnyObject | undefined); | |
| export const replaceElement = <P>( | |
| element: React.ReactNode, | |
| replacement: React.ReactNode, | |
| props?: RenderProps, | |
| ) => { | |
| if (!React.isValidElement<P>(element)) { | |
| return replacement; | |
| } | |
| return React.cloneElement<P>( | |
| element, | |
| typeof props === 'function' ? props(element.props || {}) : props, | |
| ); | |
| }; | |
| export function cloneElement<P>(element: React.ReactNode, props?: RenderProps) { | |
| return replaceElement<P>(element, element, props) as React.ReactElement<P>; | |
| } | |