# react-aux

> A self-eradicating component for rendering multiple elements.

Latest version **1.1.0** (published 2017-10-20) · BSD-3-Clause license · 0 weekly downloads

## Install

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

## 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.1.0 |
| Published | 2017-10-20 |
| First published | 2017-08-06 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 323 |
| Maintainers | gajus |
| Keywords | react |

## Links

- npm: https://www.npmjs.com/package/react-aux
- Repository: https://github.com/gajus/react-aux
- Homepage: https://github.com/gajus/react-aux#readme
- Issues: https://github.com/gajus/react-aux/issues
- npm.io page: https://npm.io/package/react-aux

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2017-10-20
- 1.0.1 — 2017-08-31
- 1.0.0 — 2017-08-06

## README

# react-aux

[![NPM version](http://img.shields.io/npm/v/react-aux.svg?style=flat-square)](https://www.npmjs.org/package/react-aux)
[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)

A self-eradicating component for rendering multiple elements.

## Motivation

Prior to React v16, returning multiple elements from a component required to wrap them in an auxiliary element, e.g.

```js
const Root = () => {
  return <div>
    <p>Hello, World!</p>
    <p>I am a demo for react-aux.</p>
  </div>;
};

```

The latter produces the following DOM:

```html
<div>
  <p>Hello, World!</p>
  <p>I am a demo for react-aux.</p>
</div>

```

Starting with React v16, a single component can return multiple components without a wrapping element, e.g.

```js
const Aux = (props) => {
  return props.children;
};

const Root = () => {
  return <Aux>
    <p>Hello, World!</p>
    <p>I am a demo for react-aux.</p>
  </Aux>;
};

```

The latter produces paragraph elements without the wrapping node:

```html
<p>Hello, World!</p>
<p>I am a demo for react-aux.</p>

```

As you can see, `react-aux` is literally just 3 lines of code. Therefore, you could implement it in your own codebase without using `react-aux`. However, `props => props.children` on its own does not explain the intent. `react-aux` as an abstraction serves the purpose of enabling a self-documenting code, i.e. the next time you see someone doing:

```js
import Aux from 'react-aux';

const Root = () => {
  return <Aux>
    <p>Hello, World!</p>
    <p>I am a demo for react-aux.</p>
  </Aux>;
};

```

You will know exactly what is the intent of the code.

## Related articles

* [Using React v16 to create self-destructing components](https://medium.com/@gajus/using-react-v16-to-create-self-destructing-components-de8e4eb61d0f)

## FAQ

### Whats the difference from using an array?

You can use an array if you assign each `React$Element` a pseudo-property `key` with a unique value, e.g. 

```js
import Aux from 'react-aux';

const Root = () => {
  return [
    <p key='p1'>Hello, World!</p>,
    <p key='p2'>I am a demo for react-aux.</p>
  ];
};

```

However, it requires manually ensuring key uniqueness and I am too [lazy](http://threevirtues.com/) for this.

### Whats with the name?

"aux" is a convention I've been using ever since I remember starting to write HTML/ CSS. Auxiliary element is something that does not have semantic purpose but exist for the purpose of grouping elements, styling, etc.

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