UNPKG

367 BJavaScriptView Raw
1import React from 'react';
2import { isFragment } from 'react-is';
3export function traverseReactNode(children, fn) {
4 let i = 0;
5 function handle(target) {
6 React.Children.forEach(target, child => {
7 if (!isFragment(child)) {
8 fn(child, i);
9 i += 1;
10 } else {
11 handle(child.props.children);
12 }
13 });
14 }
15 handle(children);
16}
\No newline at end of file