New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

annotated-prop-types

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

annotated-prop-types

Add extra info to your React PropTypes.

0.3.0
latest
Source
npm
Version published
Weekly downloads
20
1900%
Maintainers
1
Weekly downloads
 
Created
Source

annotated-prop-types

Sometimes, you might find it useful to extract information from your React components on runtime using their propTypes. However, this can be tragically difficult to extract meaningful information from because PropTypes is just a collection of functions.

Using this module adds additional properties onto the PropType validators, which you can use to extract extra information about what the propTypes actually are.

Exposed Properties

The following properties are exposed on every PropType:

  • typeName - Matches the name of the validator on PropTypes, such as string, 'bool', 'oneOf', etc.
  • typeRequired - If .isRequired was used in the propTypes definition, this is true. Otherwise, it is false.

For PropTypes that you pass an argument to (such as shape and oneOf), there's an additional property:

  • typeChecker - The argument that you passed to the PropType function.

Example

import 'annotated-prop-types';
import PropTypes from 'prop-types';

console.log(PropTypes.string.typeName); // 'string'
console.log(PropTypes.string.typeRequired); // false
console.log(PropTypes.string.isRequired.typeRequired); // true

console.log(PropTypes.oneOf(['hello', 'world']).typeName); // 'oneOf'
console.log(PropTypes.oneOf(['hello', 'world']).typeRequired); // false
console.log(PropTypes.oneOf(['hello', 'world']).typeChecker); // ['hello', 'world']
console.log(PropTypes.oneOf(['hello', 'world']).isRequired.typeRequired); // true

Keywords

react

FAQs

Package last updated on 19 Apr 2017

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