Skip to content

Commit

Permalink
feat(react): add cloneReactChildren function
Browse files Browse the repository at this point in the history
  • Loading branch information
wewoor committed Nov 27, 2020
1 parent 0c52a1c commit 3c38959
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/react/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Children, cloneElement, isValidElement } from "react";

/**
* Clone react children props
* @param children ReactNode
* @param props Parent props
*/
export function cloneReactChildren<P>(children: React.ReactNode, props: P): ReactNode {
return Children.map(children, child => {
if (isValidElement(child)) {
return cloneElement(child, props);
}
return child;
})
}
1 change: 1 addition & 0 deletions src/react/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './component';
export * from './mapState';
export * from './helper';

0 comments on commit 3c38959

Please sign in to comment.