UNPKG

@atlaskit/renderer

Version:
28 lines (27 loc) 1.03 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.recursivelyInjectProps = recursivelyInjectProps; var _react = _interopRequireDefault(require("react")); /** * Helper function to recursively injects props to * all valid children react nodes. */ function recursivelyInjectProps(children, propsToInject) { return _react.default.Children.toArray(children).map(function (child) { // Cannot add a prop to an invalid element, so just return the child if (! /*#__PURE__*/_react.default.isValidElement(child)) { return child; } // Recursive call if child has nested children if (child.props.children) { child = /*#__PURE__*/_react.default.cloneElement(child, { children: recursivelyInjectProps(child.props.children, propsToInject) }); } // Add props to react child node return /*#__PURE__*/_react.default.cloneElement(child, propsToInject); }); }