Files
Speedtest-Tracker/conf/site/node_modules/react-bootstrap/esm/ElementChildren.js
Henry Whitaker ea5808047f Tweaked gitignore
gitignore removed all composer and npm files, so automated builds would fail
2020-04-12 21:24:03 +01:00

32 lines
917 B
JavaScript
Vendored

import React from 'react';
/**
* Iterates through children that are typically specified as `props.children`,
* but only maps over children that are "valid elements".
*
* The mapFunction provided index will be normalised to the components mapped,
* so an invalid component would not increase the index.
*
*/
function map(children, func) {
var index = 0;
return React.Children.map(children, function (child) {
return React.isValidElement(child) ? func(child, index++) : child;
});
}
/**
* Iterates through children that are "valid elements".
*
* The provided forEachFunc(child, index) will be called for each
* leaf child with the index reflecting the position relative to "valid components".
*/
function forEach(children, func) {
var index = 0;
React.Children.forEach(children, function (child) {
if (React.isValidElement(child)) func(child, index++);
});
}
export { map, forEach };