npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prop-types-extra

v1.1.1

Published

React PropType Utilities

Downloads

7,970,768

Readme

prop-types-extra Travis npm

Additional PropTypes for React.

Usage

import elementType from 'prop-types-extra/lib/elementType';
// or
import { elementType } from 'prop-types-extra';

const propTypes = {
  someProp: elementType,
};

If you want to minimize bundle size, import only the validators you use via:

import elementType from 'prop-types-extra/lib/elementType'

Guide

Installation

$ npm i -S react
$ npm i -S prop-types-extra

all(...validators)

This validator checks that all of the provided validators pass.

const propTypes = {
  vertical:  PropTypes.bool.isRequired,

  block: all(
    PropTypes.bool.isRequired,
    ({ block, vertical }) => (
      block && !vertical ?
        new Error('`block` requires `vertical` to be set to have any effect') :
        null
    ),
  ),
};

The provided validators will be validated in order, stopping on the first failure. The combined validator will succeed only if all provided validators succeed.

As in the example, this can be used to make a type assertion along with additional semantic assertions.

componentOrElement

Checks that the value is a ReactComponent or a DOMElement.

const propTypes = {
  container: componentOrElement,
  requiredContainer: componentOrElement.isRequired,
};

This ensures that the value is of the right type to pass to ReactDOM.findDOMNode(), for cases where you need a DOM node.

deprecated(validator, reason)

This validator will log a deprecation warning if the value is present.

const propTypes = {
  collapsable: deprecated(PropTypes.bool, 'Use `collapsible` instead.'),
};

If the collapsable prop above is specified, this validator will log the warning:

The prop `collapsable` of `MyComponent` is deprecated. Use `collapsible` instead.

This validator warns instead of failing on invalid values, and will still call the underlying validator if the deprecated value is present.

This validator will only warn once on each deprecation. To clear the cache of warned messages, such as for clearing state between test cases intended to fail on deprecation warnings, call deprecated._resetWarned().

elementType

Checks that the value is a React element type. This can be either a string (for DOM elements) or a ReactClass (for composite components).

const propTypes = {
  Component: elementType.isRequired,
};

This ensures that the value of is the right type for creating a ReactElement, such as with <Component {...props} />.

isRequiredForA11y(validator)

This validator checks that the value required for accessibility are present.

const propTypes = {
  id: isRequiredForA11y(PropTypes.string),
};

If the id prop above is not specified, the validator will fail with:

The prop `id` is required to make `MyComponent` accessible for users of assistive technologies such as screen readers.