react-children-utilities

Recursive and extended utils for React children opaque data structure.

Usage no npm install needed!

<script type="module">
  import reactChildrenUtilities from 'https://cdn.skypack.dev/react-children-utilities';
</script>

README

React Children Utilities

Recursive and extended utils for React children opaque data structure.

Gzip Bundle Size Build Status Coverage Status Known Vulnerabilities

All Contributors npm version npm downloads

Installation

Available as a package and can be added to your application with npm or yarn after installing the peer dependency react

# with yarn
yarn add react-children-utilities react

# with npm
npm install --save react-children-utilities

Usage

This package extends the existing React.Children utilities, you can import it as a whole.

import React from 'react';
import Children from 'react-children-utilities';

const MyComponent = ({ children }) => {
  const onlySpans = Children.filter(children, (child) => child.type === 'span');
  return <div>{onlySpans}</div>;
};

Also you can import only the function you need

import React from 'react';
import { filter } from 'react-children-utilities';

const MyComponent = ({ children }) => {
  const onlySpans = filter(children, (child) => child.type === 'span');
  return <div>{onlySpans}</div>;
};

API documentation

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Fernando Pasik

🐛 💻 📖 🤔

mrm007

🐛 💻

yosef langer

🐛 💻

iyegoroff

🐛 💻

Mark Allen

🐛 💻

Ryosuke IWANAGA

🐛 💻

Daniel Pinyol

🐛 💻

Brian Bartholomew

🐛 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT (c) 2016 Fernando Pasik