prop-types-nullable
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Prop-Types Nullable

Small convenience function for prop-types which allows explicitly null props but rejects omissions.

Install dependency

npm install --save prop-types-nullable

Usage

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 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 https://github.com/facebook/react/issues/3163 for a discussion around adding similar functionality to the core prop-types project.

/prop-types-nullable/

    Package Sidebar

    Install

    npm i prop-types-nullable

    Weekly Downloads

    130

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    3.88 kB

    Total Files

    5

    Last publish

    Collaborators

    • davidje13