Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ElementChildren.js 917B

1234567891011121314151617181920212223242526272829303132
  1. import React from 'react';
  2. /**
  3. * Iterates through children that are typically specified as `props.children`,
  4. * but only maps over children that are "valid elements".
  5. *
  6. * The mapFunction provided index will be normalised to the components mapped,
  7. * so an invalid component would not increase the index.
  8. *
  9. */
  10. function map(children, func) {
  11. var index = 0;
  12. return React.Children.map(children, function (child) {
  13. return React.isValidElement(child) ? func(child, index++) : child;
  14. });
  15. }
  16. /**
  17. * Iterates through children that are "valid elements".
  18. *
  19. * The provided forEachFunc(child, index) will be called for each
  20. * leaf child with the index reflecting the position relative to "valid components".
  21. */
  22. function forEach(children, func) {
  23. var index = 0;
  24. React.Children.forEach(children, function (child) {
  25. if (React.isValidElement(child)) func(child, index++);
  26. });
  27. }
  28. export { map, forEach };