Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/udivankin/react-map-children
- Owner: udivankin
- Created: 2017-07-24T16:03:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-25T12:18:19.000Z (over 7 years ago)
- Last Synced: 2024-12-20T03:38:31.689Z (14 days ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
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']
```