# react-conditionally

> HOC for conditional rendering

Latest version **1.0.3** (published 2018-05-24) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-05-24 |
| First published | 2018-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Janek Lasocki-Biczysko |
| Maintainers | janek |

## Links

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

## Recent versions

- 1.0.3 (latest) — 2018-05-24
- 1.0.2 — 2018-02-11

## README

# react-conditionally

> HOC that provides a simple wrapper API for conditional rendering. It's [very simple](src/index.js).

[![NPM](https://img.shields.io/npm/v/react-conditionally.svg)](https://www.npmjs.com/package/react-conditionally)

## Install

```bash
npm install --save react-conditionally
```

## API

### `conditionally(propsPredicate, WrappedComponent)`

- `propsPredicate`: A predicate function that accepts a `props` object as its single argument.
- `WrappedComponent`: The component to render if `propsPredicate` returns truthy

## Usage

On it's own:
```jsx
// ConditionalMyComponent.js
import React from 'react'
import { conditionally } from 'react-conditionally'
import MyComponent from './MyComponent'

export default conditionally(
  props => !!props.data,
  MyComponent
)

```

Works well with `react-redux`:
```jsx
import { connect } from 'react-redux'
import { conditionally } from 'react-conditionally'
import MyComponent from './MyComponent'

const mapStateToProps = state => ({ data: state.data });

export default connect(mapStateToProps)(
  conditionally(
    props => !!props.data,
    MyComponent
  )
);
```

---

Boilerplate'd from [react-modern-library-boilerplate](https://github.com/transitive-bullshit/react-modern-library-boilerplate)

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