Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/udivankin/react-map-children

Map React component's children recursively
https://github.com/udivankin/react-map-children

Last synced: 3 days ago
JSON representation

Map React component's children recursively

Awesome Lists containing this project

README

        

# React-map-children
Iterates through given React component tree to gather some data

## Install
Via npm:
```bash
npm install --save react-map-children
```

## Usage

```javascript
import React from 'react';
import mapRecursive from 'react-map-children';

const Route = ({ children, path }) => (
{children}
);

const routes = (

Index
About
Contacts

);

const paths = mapRecursive(
routes,
route => (React.isValidElement(route) ? route.props.path : null),
).filter(Boolean);

console.log(paths); // ['/', 'index', 'about', 'contacts']
```