GithubHelp home page GithubHelp logo

react-prop-types's Introduction

DEPRECATED!!!!!!

(it's the same thing)

react-prop-types Travis npm

Additional PropTypes for React.

Usage

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

const propTypes = {
  someProp: elementType,
};

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

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

Guide

Installation

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

This validator checks that all of the provided validators pass.

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

  block: all(
    React.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.

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.

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

const propTypes = {
  collapsable: deprecated(React.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().

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} />.

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

const propTypes = {
  id: isRequiredForA11y(React.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.

react-prop-types's People

Contributors

aabenoja avatar aldredcz avatar alexkval avatar davidfou avatar jochenberger avatar jquense avatar mtscout6 avatar taion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-prop-types's Issues

Uncaught TypeError: Cannot read property 'all' of undefined

I'm trying to follow the example however, I got the error below.

import CustomPropTypes from 'react-prop-types';

propTypes: {
text: CustomPropTypes.all(...)
}

Error:

Uncaught TypeError: Cannot read property 'all' of undefined

Also, when I console.log(), the value of CustomPropTypes is undefined.

console.log({CustomPropTypes});
Object {CustomPropTypes: undefined}

Transfering package name

ping: @react-bootstrap/collaborators especially @AlexKVal who wrote the original code here.

The React team has been working towards splitting PropTypes out of react core and would like to use the name react-prop-types (for obvious reasons). I didn't personally see a problem with giving up the name but would like folks to weigh in if they do!

@acdlite said they'd help make sure we don't run into any issues (major version bump, a comment noting where the original went, etc) So from a technical prospective there shouldn't be any issues with packages that depend on this, except that to upgrade it we'll need to point to the new package.

Thoughts? concerns?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.