Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/davidje13/prop-types-nullable
- Owner: davidje13
- License: mit
- Created: 2019-03-23T15:11:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-27T20:47:55.000Z (over 2 years ago)
- Last Synced: 2024-11-19T23:08:47.440Z (about 1 month ago)
- Topics: prop-types, react
- Language: JavaScript
- Homepage:
- Size: 78.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.