# react-composite

> Wrap components without adding an element to the DOM.

Latest version **1.0.0** (published 2017-11-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-composite
pnpm add react-composite
yarn add react-composite
bun add react-composite
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-11-25 |
| First published | 2017-11-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Luka Bracanovic |
| Maintainers | mr_br |
| Keywords | React, React Composite |

## Links

- npm: https://www.npmjs.com/package/react-composite
- npm.io page: https://npm.io/package/react-composite

## Recent versions

- 1.0.0 (latest) — 2017-11-25

## README

# React Composite

Wrap components without adding an element to the DOM.

## Description

Use Composite when you want to return more than one child and you don't need additional element around children.

In React > 16 Component may return more then one child components by returning an array. Downside is that you don't write "pure" JSX and you have to worry about component keys. You can wrap your children with a html element but you get an additional and unnecessary layer.

To avoid both array pattern and html element wrapper use Composite component. It allows you to wrap children without need to define keys and it doesn't add an element to the dom.

Composite component is a pass-through, it just pass children down the chain leaving React "core" to take care of the rest.

## Examples

Multiple children

- without Composite (HTML element wrapper)
```javascript
// Without Composite
const Username = () => (
    <div>
        <span>User: </span>
        <span>MrBr</span>
    </div>
);
// DOM
// <div>
//  <span>User: </span>
//  <span>MrBr</span>
// </div>
```

- with Composite
```javascript
const Username = () => (
    <Composite>
        <span>User: </span>
        <span>MrBr</span>
    </Composite>
);

// DOM
// <span>User: </span>
// <span>MrBr</span>
```

Children as Function pattern

- without Composite (with Array pattern)
```javascript
const Username = () => (
    <GetUsername>
        {(username) => [
            <span key="label">User: </span>,
            <span key="username">{username}</span>
        ]}
    </GetUsername>
);
```

- with Composite
```javascript
const Username = () => (
    <GetUsername>
        {(userName) => (
            <Composite>
                <span>User: </span>
                <span>{userName}</span>
            </Composite>
        )}
    </GetUsername>
);
```

---
_Source: https://npm.io/package/react-composite · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
