MCPcopy
hub / github.com/facebook/react / mapChildren

Function mapChildren

packages/react/src/ReactChildren.js:357–372  ·  view source on GitHub ↗

* Maps children that are typically specified as `props.children`. * * See https://reactjs.org/docs/react-api.html#reactchildrenmap * * The provided mapFunction(child, index) will be called for each * leaf child. * * @param {?*} children Children tree container. * @param {function(*, int)} fu

(
  children: ?ReactNodeList,
  func: MapFunc,
  context: mixed,
)

Source from the content-addressed store, hash-verified

355 * @return {object} Object containing the ordered map of results.
356 */
357function mapChildren(
358 children: ?ReactNodeList,
359 func: MapFunc,
360 context: mixed,
361): ?Array<React$Node> {
362 if (children == null) {
363 // $FlowFixMe limitation refining abstract types in Flow
364 return children;
365 }
366 const result: Array<React$Node> = [];
367 let count = 0;
368 mapIntoArray(children, result, '', '', function (child) {
369 return func.call(context, child, count++);
370 });
371 return result;
372}
373
374/**
375 * Count the number of children that are typically specified as

Callers 3

countChildrenFunction · 0.85
forEachChildrenFunction · 0.85
toArrayFunction · 0.85

Calls 1

mapIntoArrayFunction · 0.85

Tested by

no test coverage detected