You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

prop-types-nullable

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prop-types-nullable

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

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
45
-32.84%
Maintainers
1
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 29 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts