native-base
Version:
Essential cross-platform UI components for React Native
22 lines (19 loc) • 452 B
text/typescript
import React from 'react';
const getIndexedChildren = (
children: React.ReactNode,
startingIndex?: number
) => {
let counter = startingIndex ? startingIndex - 1 : -1;
const indexedChildren = React.Children.map(children, (child: any) => {
counter++;
return React.cloneElement(
child,
{
index: counter,
},
child.props.children
);
});
return indexedChildren;
};
export default getIndexedChildren;