Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/davidje13/prop-types-nullable

a small convenience function for allowing explicitly null props with the prop-types package
https://github.com/davidje13/prop-types-nullable

prop-types react

Last synced: 27 days ago
JSON representation

a small convenience function for allowing explicitly null props with the prop-types package

Awesome Lists containing this project

README

        

# Prop-Types Nullable

Small convenience function for
[`prop-types`](https://github.com/facebook/prop-types) which allows
explicitly null props but rejects omissions.

## Install dependency

```bash
npm install --save prop-types-nullable
```

## Usage

This builds on top of
[`prop-types`](https://github.com/facebook/prop-types),
so see that project's documentation for the basics of the API.

Simple usage:

```javascript
const nullable = require('prop-types-nullable');

MyReactClass.propTypes = {
foobar: nullable(PropTypes.func).isRequired,
};

// foobar is now a required property, but can be explicitly null
```

It is possible to use `nullable` without `isRequired`, but this is
pointless (as null will be allowed for a non-required property anyway).
This project maintains the need for `isRequired` for consistency with
the `prop-types` API, and to better integrate with linting rules.

See for a discussion
around adding similar functionality to the core `prop-types` project.