# conditional-wrapper

> A React component with which you can conditionally wrap child components

Latest version **1.0.3** (published 2021-10-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install conditional-wrapper
pnpm add conditional-wrapper
yarn add conditional-wrapper
bun add conditional-wrapper
```

## 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 | 2021-10-01 |
| First published | 2021-10-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 463.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Michael van den Oudenalder |
| Maintainers | michaelvdo |
| Keywords | react, typescript, HoC |

## Links

- npm: https://www.npmjs.com/package/conditional-wrapper
- Repository: https://github.com/michaelvdo/conditional-wrapper
- Homepage: https://github.com/michaelvdo/conditional-wrapper#readme
- Issues: https://github.com/michaelvdo/conditional-wrapper/issues
- npm.io page: https://npm.io/package/conditional-wrapper

## 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.0.3 (latest) — 2021-10-01
- 1.0.2 — 2021-10-01
- 1.0.1 — 2021-10-01
- 1.0.0 — 2021-10-01

## README

# Conditional Wrapper component for React

## Reason for this component
Occasionally, you may want to wrap a React component with another component, but only when a certain condition is true. There's no native React component that can do this for you, and many Higher Order Components out there add a ton of options for conditionally rendering a wrapping component.

This component does only one thing: Conditionally wrap a child component with a wrapping component, based on a condition that's passed as a prop.

## Installation
```
npm i conditional-wrapper
```

## Usage
```
import { ConditionalWrapper } from 'conditional-wrapper';

const condition = true; // any truthy or falsy value

<ConditionalWrapper
	condition={condition}
	wrapper={(children) => <div>This is the wrapper component, followed by the children: {children}</div>}>
		<p>This is the child component.</p>
</ConditionalWrapper>
```

## Props

### `condition: boolean`
The `condition` prop takes a `boolean` value that indicates whether the wrapper should be rendered or not.

### `wrapper: (children: JSX.Element | JSX.Element[]) => JSX.Element`
The `wrapper` prop takes a `function` with a parameter that represents the `children` prop of the `<ConditionalWrapper />`. The function returns the wrapping component that should be rendered in case the `condition` prop evaluates to `true`.

### `children: JSX.Element | JSX.Element[]`
The `children` prop represents the direct children of the `<ConditionalWrapper />` component.

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