1.0.1 • Published 5 years ago
prop-types-nullable v1.0.1
Prop-Types Nullable
Small convenience function for
prop-types which allows
explicitly null props but rejects omissions.
Install dependency
npm install --save prop-types-nullableUsage
This builds on top of
prop-types,
so see that project's documentation for the basics of the API.
Simple usage:
const nullable = require('prop-types-nullable');
MyReactClass.propTypes = {
foobar: nullable(PropTypes.func).isRequired,
};
// foobar is now a required property, but can be explicitly nullIt 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 https://github.com/facebook/react/issues/3163 for a discussion
around adding similar functionality to the core prop-types project.
1.0.1
5 years ago