Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/birkir/react-children-addons

React Children Addons
https://github.com/birkir/react-children-addons

Last synced: about 2 months ago
JSON representation

React Children Addons

Awesome Lists containing this project

README

        

![](https://img.shields.io/npm/v/react-children-addons.svg?&style=flat-square) ![](https://img.shields.io/bundlephobia/min/react-children-addons.svg?&style=flat-square) ![](https://img.shields.io/npm/l/react-children-addons.svg?&style=flat-square) ![](https://img.shields.io/david/birkir/react-children-addons.svg?&style=flat-square) ![](https://img.shields.io/npm/dw/react-children-addons.svg?&style=flat-square)
# react-children-addons

React children utilities and addons

```bash
npm install react-children-addons -S

# or

yarn add react-children-addons -S
```

## API Methods
- [toFlatArray](#toflatarray)
- [mapFlat](#mapflat)

### toFlatArray

Takes children and flattens all React.Fragments into a single array

```jsx
import { toFlatArray } from 'react-children-addons';

function List({ children }) {
console.log(toFlatArray(children));
}

  • Item

  • <>
  • Another Item

  • >

    ```
    ```jsx
    [

  • Item
  • ,
  • Another Item
  • ]
    ```

    ### mapFlat

    Same as `toFlatArray` but with a map function

    ```jsx
    import React from 'react';
    import { mapFlat } from 'react-children-addons';

    function List({ children }) {
    return (


      {mapFlat(children, child => React.cloneElement(child, { className: 'link' }))}

    );
    }

  • Item

  • <>
  • Another Item

  • >

    <>
  • Nested Item

  • >

    ```
    ```html






    ```

    ## Todo

    Add tests, changelog and more ideas for addons.