An open API service indexing awesome lists of open source software.

https://github.com/drawbotics/if-only

A tiny react component that only renders children if a condition if met.
https://github.com/drawbotics/if-only

Last synced: 2 months ago
JSON representation

A tiny react component that only renders children if a condition if met.

Awesome Lists containing this project

README

        

# If-only

A tiny react component that only renders children if a condition if met.

## Installation

Install it using yarn:

```bash
$ yarn add if-only
```

## Usage

### Simple usage

```javascript
const Component = () => (


// ...

// will render if someCondition is true


);
```

### Advanced usage

If there's only one child, then it's going to render that child, but if there's more than one child, then, it's going to wrap them with an external component. That external component depends on the following props.

#### Manually specifying the external component

This takes precedence over any other prop.

```javascript
const Component = () => (


// ...

// will render if someCondition is true wrapping it with


);
```

#### Using a default external component

If `inline` is specified, it will wrap the children with a `span` tag. Otherwise, it will just use a `div` tag.

```javascript
const Component = () => (


// ...

// Will render if someCondition is true wrapping it with a




);
```

#### Specifying style and className for external component

If a external component is to be rendered, the `className` and `style` props can be specified on the `If` component and
it will pass them down to the external component.

```javascript
const Component = () => (


// ...

// Will render if someCondition is true. External
will have className="CustomName"


);
```

## License

MIT. See [LICENSE](LICENSE) for detail.