import { Children , isValidElement , cloneElement } from 'react' ; import { isString } from 'lodash' ; param nodes param extraProps export default function cloneNodes ( nodes , props ) { return Children . map ( nodes , ( node ) => { if ( ! isValidElement ( node ) ) { return node ; } /**
         * if the node is a primitive DOM element rather than a React element, clone it but don't pass it props
         * React elements (primitive DOM nodes) type property is a string while React coponents will be of type function or class
         * see this for more info: https://reactjs.org/blog/2015/12/18/react-components-elements-and-instances.html
         */ if ( isString ( node . type ) ) { return cloneElement ( node ) ; } return cloneElement ( node , { ... props } ) ; } ) ; }