Socket
Socket
Sign inDemoInstall

prop-types-nullable

Package Overview
Dependencies
5
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

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


Version published
Weekly downloads
154
increased by12.41%
Maintainers
1
Install size
3.79 kB
Created
Weekly downloads
 

Readme

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

Last updated on 29 Aug 2020

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc