Socket
Socket
Sign inDemoInstall

create-prop-types

Package Overview
Dependencies
3
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    create-prop-types

Create custom React prop types with ease


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
37.9 kB
Created
Weekly downloads
 

Readme

Source

create-prop-types

A lightweight helper library to create custom React prop types.

Getting started

Install

npm install create-prop-types --save-dev

Create a custom prop type

// ./prop-types/Iterable.js

import createPropType from 'create-prop-types';
import { Iterable } from 'immutable';

const IterablePropType = createPropType({
  predicate: propValue => Iterable.isIterable(propValue)
});

export default IterablePropType;

Use the custom prop type

import Iterable from './prop-types/Iterable';

export default class MyComponent extends React.Component {
  static propTypes = {
    propA: Iterable,
    propB: Iterable.isRequired
  }
}

API

predicate: (propValue: any) => boolean

A predicate function to satisfy in order to consider the prop value as valid.

Example
const CustomPropType = createPropType({
  predicate: propValue => (propValue !== 'foo')
});

export default CustomPropType;

warnings?: Warnings

Optional custom warning messages.

type Warnings = {
  missing?: WarningResolver,
  invalid?: WarningResolver
}

type WarningResolver = (propName: string, propValue: any, componentName: string) => string
Example
const CustomPropType = createPropType({
  predicate: propValue => ...,
  warnings: {
    missing: (propName, propValue, componentName) => {
      return `Required prop "${propName}" is missing in "${componentName}" component.`;
    }
  }
});

export default CustomPropType;

License

This project is licensed under MIT License. See the license file for more details.

Keywords

FAQs

Last updated on 07 Mar 2018

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