# react-required-if

> React PropType to conditionally add `.isRequired` based on other props

Latest version **1.0.3** (published 2017-11-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-required-if
pnpm add react-required-if
yarn add react-required-if
bun add react-required-if
```

## 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.0.3 |
| Published | 2017-11-11 |
| First published | 2016-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | James Kyle |
| Maintainers | thejameskyle |

## Links

- npm: https://www.npmjs.com/package/react-required-if
- npm.io page: https://npm.io/package/react-required-if

## Recent versions

- 1.0.3 (latest) — 2017-11-11
- 1.0.2 — 2017-10-19
- 1.0.1 — 2017-05-03
- 1.0.0 — 2016-04-11

## README

# react-required-if

> React PropType to conditionally add `.isRequired` based on other props

## Install

```sh
$ npm install --save react-required-if
```

## Usage

```js
import React, {PropTypes} from 'react';
import requiredIf from 'react-required-if';

export default class Component extends React.Component {
  static propTypes = {
    disabled: PropTypes.bool,
    onClick: requiredIf(PropTypes.func, props => !props.disabled)
  };

  render() {
    return <button onClick={this.props.onClick}>Click Me</button>
  }
}
```

**Result:**

```js
import React from 'react';
import {render} from 'react-dom';
import Component from './Component';

render(
  <div>
    <Component onClick={() => {})/> // ok
    <Component disabled={true}/> // ok
    <Component/> // NOooooooo
  </div>,
  document.getElementById('root')
);
```

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