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

https://github.com/jamiebuilds/react-required-if

React PropType to conditionally add `.isRequired` based on other props
https://github.com/jamiebuilds/react-required-if

prop-types props react validation

Last synced: 11 months ago
JSON representation

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

Awesome Lists containing this project

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 Click Me
}
}
```

**Result:**

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

render(


{})/> // ok
// ok
// NOooooooo
,
document.getElementById('root')
);
```