# @brenodega28/react-conditionals

> React Conditionals is a small React package for a better readability when using conditional rendering (mostly when nesting many conditionals). Got inspiration from v-if in Vue.

Latest version **0.1.0** (published 2020-05-26) · 0 weekly downloads

## Install

```sh
npm install @brenodega28/react-conditionals
pnpm add @brenodega28/react-conditionals
yarn add @brenodega28/react-conditionals
bun add @brenodega28/react-conditionals
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2020-05-26 |
| First published | 2020-05-26 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 22.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | brenodega28 |

## Links

- npm: https://www.npmjs.com/package/@brenodega28/react-conditionals
- npm.io page: https://npm.io/package/@brenodega28/react-conditionals

## Dependencies (6)

- [react](https://npm.io/package/react.md) ^16.13.1
- [react-dom](https://npm.io/package/react-dom.md) ^16.13.1
- [react-scripts](https://npm.io/package/react-scripts.md) 3.4.1
- [@testing-library/react](https://npm.io/package/@testing-library/react.md) ^9.3.2
- [@testing-library/jest-dom](https://npm.io/package/@testing-library/jest-dom.md) ^4.2.4
- [@testing-library/user-event](https://npm.io/package/@testing-library/user-event.md) ^7.1.2

## Recent versions

- 0.1.0 (latest) — 2020-05-26

## README

# React Conditionals

<b>React Conditionals</b> is a small React package for a better readability when using conditional rendering (mostly when nesting many conditionals). Got inspiration from v-if in Vue.

#### Before React Conditionals

```javascript
const Article = ({ logged }) => (
  <div>
    <h1>Some cool article</h1>
    <p>Free part of the article...</p>
    {logged ? (
      <p>Rest of the article</p>
    ) : (
      <h2>Please login to see the rest of the article</h2>
    )}
  </div>
);
```

#### After React Conditionals

```javascript
import {If, Else} from 'react-conditionals';

const Article = ({ logged }) => (
  <div>
    <h1>Some cool article</h1>
    <p>Free part of the article...</p>
    <If conditional={logged}>
      <p>Rest of the article</p>
    </If>
    <Else>
      <h2>Please login to see the rest of the article</h2>
    </Else>
    )}
  </div>
```

That's it! The If component receive the boolean conditional prop that will determine if the component should be rendered or not. The Else component <b>needs to be right after the If component it should track!</b> (or else it will never show anything!)

## How it works

<b>If</b> the If component doesn't render the desired children, it will render and empty div with a 'react-conditionals-false' class which the Else component will read.

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