@atlaskit/renderer
Version:
Renderer component
21 lines • 739 B
JavaScript
import React from 'react';
/**
* Helper function to recursively injects props to
* all valid children react nodes.
*/
export function recursivelyInjectProps(children, propsToInject) {
return React.Children.toArray(children).map(child => {
// Cannot add a prop to an invalid element, so just return the child
if (! /*#__PURE__*/React.isValidElement(child)) {
return child;
}
// Recursive call if child has nested children
if (child.props.children) {
child = /*#__PURE__*/React.cloneElement(child, {
children: recursivelyInjectProps(child.props.children, propsToInject)
});
}
// Add props to react child node
return /*#__PURE__*/React.cloneElement(child, propsToInject);
});
}