"use strict"; // NOTE: Only use this where absolutely needed! Normally, the context API should be preferred where possible. const React = require("react"); module.exports = function childrenWithProps(children, mapper) { return React.Children.map(children, (child, i) => { let extraProps = (typeof mapper === "function") ? mapper(child, i) : mapper; if (extraProps != null) { // FIXME: Do we need to check React.isValidElement here, to deal with eg. text nodes? Or is that handled internally by React.cloneElement? return React.cloneElement(child, extraProps); } else { return child; } }); };