Skip to content

Commit

Permalink
Update newest (#3)
Browse files Browse the repository at this point in the history
* Include CI for master branch and PR's

In accordance with facebook#19,
includes config for TravisCI to run test reports on the master branch
and PR's to the master branch.

- Includes .travis.yml config file
- Includes current CI status badge in README

Closes facebook#19.

* Point readme to correct docs for production builds (facebook#153)

After an update to the docs, the production build was pointing to an outdated link. This commit directs the link to the appropriate location in the React docs.

* 15.6.1

* Add 15.6.1 to CHANGELOG

* Updated vars with consts and lets in PropTypesProductionReact15-test.js

* Updated vars to consts and lets in PropTypesDevelopmentReact15.js

* Updated vars to consts and lets in PropTypesDevelopmentStandalone-test.js

* Updated vars to consts and lets in PropTypesProductionStandalone-test.js

* Add example for `PropTypes.exact`

* Show that shapes can have required properties

* Move explanation of `isRequired` and show it in `PropTypes.shape`

* Remove trailing spaces

* Remove fbjs dependency

* Preserve "Invariant Violation" name

* 15.6.2

* .com

* Add support for objects with a null prototype in objectOf

* Replace `hasOwnProperty` with the more robust "has" package

* Revert "Replace `hasOwnProperty` with the more robust "has" package"

This reverts commit e6a9b28.

* Inline the `has` module

* missed semicolon

* [Tests] use componentName in getPropTypeWarningMessage instead of hard-coded testComponent

* [Fix] Fix `oneOf` when used with Symbols

- Fixes error due to an attempt to coerce a Symbol to a string
- Improves formatting of the "expected" portion of the generated
  warning, outputting for example `["Symbol(A)","Symbol(B)"]` rather
  than `[null,null]`

Fixes facebook#10

* Completely remove envify in favor of loose-envify

Closes facebook#203.

* [New] Add `.elementType`

* Add license to readme

* [Fix] Support validation when hasOwnProperty is not in prototype

Closes facebook#183; relates to facebook#112.

* [Docs] fix relative release date to be absolute

* [Docs] Fix typo in example

* [New] add `PropTypes.resetWarningCache`

* [dev deps] update `loose-envify`

* `oneOf`: improve warning when multiple arguments are supplied

Adds a different warning message for multiple arguments supplied to oneOf. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]) and this should help developers identifying the error.

* [changelog] update repo links

* v15.7.0

* [Fix] avoid template literal syntax

Fixes facebook#255. Fixes facebook#254.

* v15.7.1

* [Tests] add `eslint`; run more travis tests

* [Tests] run tests with multiple react versions

* [Fix] move `loose-envify` back to production deps, for browerify usage

Fixes facebook#203

* [Tests] add additional passing tests

* [Fix] ensure nullish values in `oneOf` do not crash

Fixes facebook#256.

* [dev deps] update `browserify`

* v15.7.2

* [Docs] Improve wording for `checkPropTypes`

* [Docs] `PropTypes.node`: add link to react docs

Fixes facebook#154.

* [meta] use `in-publish` to avoid running the build on install

* `checkPropTypes`: Friendlier message when using a type checker that is not a function

* [Tests] test the build process

* [New] Add type check for validator for 'shape' and 'exact'

Fixes facebook#220.

* [Tests] fix broken tests

* [Refactor] extract `has`

* [Docs] Add instructions for intentional inclusion of validation in production.

* [New] `oneOfType`: Add expected types to warning

Adds data object to returned error in checker so that the expected types can be accessed from within oneOfType check. Also, updates the tests slightly.

Fixes facebook#9.

* [Tests] Fixed typo: 'Any type *should* accept any value'

* [Dev Deps] update `eslint`

* [Deps] update `react-is`

* [Dev Deps] update `browserify`, `bundle-collapser`, `react`, `uglifyify`, `uglifyjs`

* [Docs] Typo fix in example

Reverts an incorrect typo fix made in facebook#248.

Closes facebook#299

* [Tests] Fix spelling

* doc: highlighted the func name (facebook#321)

* [readme] Clarify usage of `elementType`

Closes facebook#334.

* [Dev Deps] update `bundle-collapser`, `eslint`, `in-publish`, `react`

* [Deps] update `react-is`

* Add a package `sideEffects` field.

* Bump sshpk from 1.13.1 to 1.16.1

Bumps [sshpk](https://github.com/joyent/node-sshpk) from 1.13.1 to 1.16.1.
- [Release notes](https://github.com/joyent/node-sshpk/releases)
- [Commits](TritonDataCenter/node-sshpk@v1.13.1...v1.16.1)

Signed-off-by: dependabot[bot] <support@github.com>

* Use GH Actions

This migrates to a more accessible platform

* [eslint] enable some rules

Additional ESLint rules: "no-multi-spaces": ["error"], "key-spacing": ["error"]
"no-multi-spaces" - Disallow multiple spaces;
"key-spacing" - Enforce consistent spacing between keys and values in object literal properties;

* Bump path-parse from 1.0.6 to 1.0.7

Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump tmpl from 1.0.4 to 1.0.5

Bumps [tmpl](https://github.com/daaku/nodejs-tmpl) from 1.0.4 to 1.0.5.
- [Release notes](https://github.com/daaku/nodejs-tmpl/releases)
- [Commits](https://github.com/daaku/nodejs-tmpl/commits/v1.0.5)

---
updated-dependencies:
- dependency-name: tmpl
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* [deps] regenerate yarn.lock

* [readme] Fix branch name (master -> main)

* [Dev Deps] update `eslint`

* [New] add `PropTypes.bigint`

Closes facebook#355

* v15.8.0

* [Tests] do not fail fast; add react 17

* [meta] Fix formatting in CHANGELOG.md

* [Tests] convert normal `it` functions to arrow functions

* [Tests] add missing test coverage

* [Fix] fix crash when a custom propType return lacks `.data`; call `hasOwnProperty` properly

Fixes facebook#369

* [Dev Deps] update `eslint`

* v15.8.1

* docs: add GH button in support of Ukraine (facebook#375)

## Summary
Our mission at Meta Open Source is to empower communities through open source, and we believe that it means building a welcoming and safe environment for all. As a part of this work, we are adding this banner in support for Ukraine during this crisis.

* [Deps] `yarn upgrade`

* build: harden ci.yml permissions

Signed-off-by: Alex <aleksandrosansan@gmail.com>

* Bump semver from 5.7.1 to 5.7.2

Bumps [semver](https://github.com/npm/node-semver) from 5.7.1 to 5.7.2.
- [Release notes](https://github.com/npm/node-semver/releases)
- [Changelog](https://github.com/npm/node-semver/blob/v5.7.2/CHANGELOG.md)
- [Commits](npm/node-semver@v5.7.1...v5.7.2)

---
updated-dependencies:
- dependency-name: semver
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump ua-parser-js from 0.7.32 to 0.7.33

Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.32 to 0.7.33.
- [Release notes](https://github.com/faisalman/ua-parser-js/releases)
- [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md)
- [Commits](faisalman/ua-parser-js@0.7.32...0.7.33)

---
updated-dependencies:
- dependency-name: ua-parser-js
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* remove production env tests as we do not have any production env tests

* update

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Alex <aleksandrosansan@gmail.com>
Co-authored-by: Joe Fraley <joefraley@protonmail.com>
Co-authored-by: Quinn Stearns <quinn@datahost.com>
Co-authored-by: Brandon Dail <brandondail@fb.com>
Co-authored-by: Brandon Dail <aweary@users.noreply.github.com>
Co-authored-by: Barry <barry@iplatform.co.za>
Co-authored-by: Christian Paul <info@jaller.de>
Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Co-authored-by: Julien Mourer <getkey@getkey.eu>
Co-authored-by: ksmolniy <k.smolniy@gmail.com>
Co-authored-by: C. T. Lin <chentsulin@gmail.com>
Co-authored-by: Jim Fitzpatrick <fitzpatrick.jim@gmail.com>
Co-authored-by: Augustin Trancart <augustin.trancart@oslandia.com>
Co-authored-by: Benoit Tremblay <trembl.ben@gmail.com>
Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com>
Co-authored-by: Joseph A. Szczesniak <NukaPunk@users.noreply.github.com>
Co-authored-by: Troy Rhinehart <troy.rhinehart@gmail.com>
Co-authored-by: Patrick Way <patrick.way@intersection.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Wojciech Maj <kontakt@wojtekmaj.pl>
Co-authored-by: NoScripter <noscripter@users.noreply.github.com>
Co-authored-by: Gregory Desfour <gregory.desfour@accedo.tv>
Co-authored-by: Asbjørn Hegdahl <asbjorn.hegdahl@creuna.no>
Co-authored-by: NoScripter <mhz_xz_tc@126.com>
Co-authored-by: rgraffbrd <31221247+rgraffbrd@users.noreply.github.com>
Co-authored-by: Josh Alling <joshralling@gmail.com>
Co-authored-by: weiluntong <weiluntong.inbox@gmail.com>
Co-authored-by: Conrad Buck <conrad@plangrid.com>
Co-authored-by: Mark McCann <mail@markmccann.me>
Co-authored-by: John Bampton <jbampton@users.noreply.github.com>
Co-authored-by: Haseeb Khan <haseebasif97@gmail.com>
Co-authored-by: G Roques <groques360@gmail.com>
Co-authored-by: Jayden Seric <me@jaydenseric.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Paul O’Shannessy <paul@oshannessy.com>
Co-authored-by: Konstantin Popov <konst.hardy@gmail.com>
Co-authored-by: Dmitry Vinnik <dmitryvinn@users.noreply.github.com>
Co-authored-by: Alex <aleksandrosansan@gmail.com>
  • Loading branch information
1 parent e66fc8c commit 5e1e5e2
Show file tree
Hide file tree
Showing 17 changed files with 3,116 additions and 2,518 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prop-types.min.js
34 changes: 34 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"root": true,
"parserOptions": {
"ecmaVersion": 5,
},
"env": {
"browser": true,
"node": true,
},
"rules": {
"no-console": "off",
"no-multi-spaces": ["error"],
"key-spacing": ["error"],
},
"overrides": [
{
"files": "**/__tests__/**/*",
"env": {
"jest": true,
"jasmine": true,
"es6": true,
},
"rules": {
"no-unused-vars": "off",
},
"parserOptions": {
"ecmaVersion": 2019,
"ecmaFeatures": {
"jsx": true,
},
},
},
],
}
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI
on:
- push
- pull_request

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
ci:
name: "Build & Test (React v${{ matrix.react_version}})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
react_version:
- "17"
- "16"
- "16.0"
- "15"
- "15.0"
- "0.14.9"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "lts/*"
cache: 'yarn'
- run: yarn install
- run: yarn add react@${{ matrix.react_version }}
- run: yarn list --pattern 'react'
- run: yarn run pretest
- run: yarn run tests-only
- run: yarn run build
80 changes: 67 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,110 @@
## 15.8.1
* [Fix] fix crash when a custom propType return lacks `.data`; call `hasOwnProperty` properly (#370)
* [meta] Fix formatting in CHANGELOG.md (#367)
* [Tests] add missing test coverage (#370)
* [Tests] convert normal `it` functions to arrow functions (#370)
* [Tests] do not fail fast; add react 17 (#366)
* [Dev Deps] update `eslint`

## 15.8.0
* [New] add `PropTypes.bigint` (#365)
* [New] `oneOfType`: Add expected types to warning (#198)
* [New] Add type check for validator for 'shape' and 'exact' (#234)
* [Fix] `checkPropTypes`: Friendlier message when using a type checker that is not a function (#51)
* [Refactor] extract `has` (#261, #125, #124)
* [readme] Fix branch name (master -> main) (#364)
* [readme] Clarify usage of `elementType` (#335)
* [docs] highlighted the func name (#321)
* [docs] Typo fix in example (#300)
* [docs] Add instructions for intentional inclusion of validation in production. (#262)
* [docs] `PropTypes.node`: add link to react docs
* [docs] Improve wording for `checkPropTypes` (#258)
* [meta] Add a package `sideEffects` field. (#350)
* [meta] use `in-publish` to avoid running the build on install
* [deps] regenerate yarn.lock
* [deps] update `react-is` (#347, #346, #345, #340, #338)
* [eslint] enable some rules (#360)
* [Tests] Use GH Actions (#363)
* [Tests] Fix spelling (#318)
* [Tests] Fixed typo: 'Any type *should* accept any value' (#281)
* [Tests] fix broken tests; test the build process
* [Dev Deps] update `browserify`, `bundle-collapser`, `eslint`, `in-publish`, `react`, `uglifyify`, `uglifyjs`

## 15.7.2
* [Fix] ensure nullish values in `oneOf` do not crash ([#256](https://github.com/facebook/prop-types/issues/256))
* [Fix] move `loose-envify` back to production deps, for browerify usage ([#203](https://github.com/facebook/prop-types/issues/203))

## 15.7.1
* [Fix] avoid template literal syntax ([#255](https://github.com/facebook/prop-types/issues/255), [#254](https://github.com/facebook/prop-types/issues/254))

## 15.7.0
* [New] Add `.elementType` ([#211](https://github.com/facebook/prop-types/pull/211))
* [New] add `PropTypes.resetWarningCache` ([#178](https://github.com/facebook/prop-types/pull/178))
* `oneOf`: improve warning when multiple arguments are supplied ([#244](https://github.com/facebook/prop-types/pull/244))
* Fix `oneOf` when used with Symbols ([#224](https://github.com/facebook/prop-types/pull/224))
* Avoid relying on `hasOwnProperty` being present on values' prototypes ([#112](https://github.com/facebook/prop-types/pull/112), [#187](https://github.com/facebook/prop-types/pull/187))
* Improve readme ([#248](https://github.com/facebook/prop-types/pull/248), [#233](https://github.com/facebook/prop-types/pull/233))
* Clean up mistaken runtime dep, swap envify for loose-envify ([#204](https://github.com/facebook/prop-types/pull/204))

## 15.6.2
* Remove the `fbjs` dependency by inlining some helpers from it ([#194](https://github.com/facebook/prop-types/pull/194)))

## 15.6.1
* Fix an issue where outdated BSD license headers were still present in the published bundle [#162](https://github.com/facebook/prop-types/issues/162)

## 15.6.0

* Switch from BSD + Patents to MIT license
* Add PropTypes.exact, like PropTypes.shape but warns on extra object keys. ([@thejameskyle](https://github.com/thejameskyle) and [@aweary](https://github.com/aweary) in [#41](https://github.com/reactjs/prop-types/pull/41) and [#87](https://github.com/reactjs/prop-types/pull/87))
* Add PropTypes.exact, like PropTypes.shape but warns on extra object keys. ([@thejameskyle](https://github.com/thejameskyle) and [@aweary](https://github.com/aweary) in [#41](https://github.com/facebook/prop-types/pull/41) and [#87](https://github.com/facebook/prop-types/pull/87))

## 15.5.10

* Fix a false positive warning when using a production UMD build of a third-party library with a DEV version of React. ([@gaearon](https://github.com/gaearon) in [#50](https://github.com/reactjs/prop-types/pull/50))
* Fix a false positive warning when using a production UMD build of a third-party library with a DEV version of React. ([@gaearon](https://github.com/gaearon) in [#50](https://github.com/facebook/prop-types/pull/50))

## 15.5.9

* Add `loose-envify` Browserify transform for users who don't envify globally. ([@mridgway](https://github.com/mridgway) in [#45](https://github.com/reactjs/prop-types/pull/45))
* Add `loose-envify` Browserify transform for users who don't envify globally. ([@mridgway](https://github.com/mridgway) in [#45](https://github.com/facebook/prop-types/pull/45))

## 15.5.8

* Limit the manual PropTypes call warning count because it has false positives with React versions earlier than 15.2.0 in the 15.x branch and 0.14.9 in the 0.14.x branch. ([@gaearon](https://github.com/gaearon) in [#26](https://github.com/reactjs/prop-types/pull/26))
* Limit the manual PropTypes call warning count because it has false positives with React versions earlier than 15.2.0 in the 15.x branch and 0.14.9 in the 0.14.x branch. ([@gaearon](https://github.com/gaearon) in [#26](https://github.com/facebook/prop-types/pull/26))

## 15.5.7

* **Critical Bugfix:** Fix an accidental breaking change that caused errors in production when used through `React.PropTypes`. ([@gaearon](https://github.com/gaearon) in [#20](https://github.com/reactjs/prop-types/pull/20))
* Improve the size of production UMD build. ([@aweary](https://github.com/aweary) in [38ba18](https://github.com/reactjs/prop-types/commit/38ba18a4a8f705f4b2b33c88204573ddd604f2d6) and [7882a7](https://github.com/reactjs/prop-types/commit/7882a7285293db5f284bcf559b869fd2cd4c44d4))
* **Critical Bugfix:** Fix an accidental breaking change that caused errors in production when used through `React.PropTypes`. ([@gaearon](https://github.com/gaearon) in [#20](https://github.com/facebook/prop-types/pull/20))
* Improve the size of production UMD build. ([@aweary](https://github.com/aweary) in [38ba18](https://github.com/facebook/prop-types/commit/38ba18a4a8f705f4b2b33c88204573ddd604f2d6) and [7882a7](https://github.com/facebook/prop-types/commit/7882a7285293db5f284bcf559b869fd2cd4c44d4))

## 15.5.6

**Note: this release has a critical issue and was deprecated. Please update to 15.5.7 or higher.**

* Fix a markdown issue in README. ([@bvaughn](https://github.com/bvaughn) in [174f77](https://github.com/reactjs/prop-types/commit/174f77a50484fa628593e84b871fb40eed78b69a))
* Fix a markdown issue in README. ([@bvaughn](https://github.com/bvaughn) in [174f77](https://github.com/facebook/prop-types/commit/174f77a50484fa628593e84b871fb40eed78b69a))

## 15.5.5

**Note: this release has a critical issue and was deprecated. Please update to 15.5.7 or higher.**

* Add missing documentation and license files. ([@bvaughn](https://github.com/bvaughn) in [0a53d3](https://github.com/reactjs/prop-types/commit/0a53d3a34283ae1e2d3aa396632b6dc2a2061e6a))
* Add missing documentation and license files. ([@bvaughn](https://github.com/bvaughn) in [0a53d3](https://github.com/facebook/prop-types/commit/0a53d3a34283ae1e2d3aa396632b6dc2a2061e6a))

## 15.5.4

**Note: this release has a critical issue and was deprecated. Please update to 15.5.7 or higher.**

* Reduce the size of the UMD Build. ([@acdlite](https://github.com/acdlite) in [31e9344](https://github.com/reactjs/prop-types/commit/31e9344ca3233159928da66295da17dad82db1a8))
* Remove bad package url. ([@ljharb](https://github.com/ljharb) in [158198f](https://github.com/reactjs/prop-types/commit/158198fd6c468a3f6f742e0e355e622b3914048a))
* Reduce the size of the UMD Build. ([@acdlite](https://github.com/acdlite) in [31e9344](https://github.com/facebook/prop-types/commit/31e9344ca3233159928da66295da17dad82db1a8))
* Remove bad package url. ([@ljharb](https://github.com/ljharb) in [158198f](https://github.com/facebook/prop-types/commit/158198fd6c468a3f6f742e0e355e622b3914048a))
* Remove the accidentally included typechecking code from the production build.

## 15.5.3

**Note: this release has a critical issue and was deprecated. Please update to 15.5.7 or higher.**

* Remove the accidentally included React package code from the UMD bundle. ([@acdlite](https://github.com/acdlite) in [df318bb](https://github.com/reactjs/prop-types/commit/df318bba8a89bc5aadbb0292822cf4ed71d27ace))
* Remove the accidentally included React package code from the UMD bundle. ([@acdlite](https://github.com/acdlite) in [df318bb](https://github.com/facebook/prop-types/commit/df318bba8a89bc5aadbb0292822cf4ed71d27ace))

## 15.5.2

**Note: this release has a critical issue and was deprecated. Please update to 15.5.7 or higher.**

* Remove dependency on React for CommonJS entry point. ([@acdlite](https://github.com/acdlite) in [cae72bb](https://github.com/reactjs/prop-types/commit/cae72bb281a3766c765e3624f6088c3713567e6d))
* Remove dependency on React for CommonJS entry point. ([@acdlite](https://github.com/acdlite) in [cae72bb](https://github.com/facebook/prop-types/commit/cae72bb281a3766c765e3624f6088c3713567e6d))


## 15.5.1
Expand All @@ -67,4 +121,4 @@

## Before 15.5.0

PropTypes was previously included in React, but is now a separate package. For earlier history of PropTypes [see the React change log.](https://github.com/facebook/react/blob/master/CHANGELOG.md)
PropTypes was previously included in React, but is now a separate package. For earlier history of PropTypes [see the React change log.](https://github.com/facebook/react/blob/HEAD/CHANGELOG.md)
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The code of conduct is described in [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md).
## Pull Requests
We actively welcome your pull requests.

1. Fork the repo and create your branch from `master`.
1. Fork the repo and create your branch from `main`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
Expand Down
54 changes: 39 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# prop-types
# prop-types [![Support Ukraine](https://img.shields.io/badge/Support-Ukraine-FFD500?style=flat&labelColor=005BBB)](https://opensource.fb.com/support-ukraine) [![Build Status](https://travis-ci.com/facebook/prop-types.svg?branch=main)](https://travis-ci.org/facebook/prop-types)

Runtime type checking for React props and similar objects.

You can use prop-types to document the intended types of properties passed to
components. React (and potentially other libraries—see the checkPropTypes()
components. React (and potentially other libraries—see the `checkPropTypes()`
reference below) will check props passed to your components against those
definitions, and warn in development if they don’t match.

Expand All @@ -22,8 +22,8 @@ var PropTypes = require('prop-types'); // ES5 with npm

### CDN

If you prefer to exclude `prop-types` from your application and use it
globally via `window.PropTypes`, the `prop-types` package provides
If you prefer to exclude `prop-types` from your application and use it
globally via `window.PropTypes`, the `prop-types` package provides
single-file distributions, which are hosted on the following CDNs:

* [**unpkg**](https://unpkg.com/prop-types/)
Expand All @@ -44,7 +44,7 @@ single-file distributions, which are hosted on the following CDNs:
<script src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.6.0/prop-types.min.js"></script>
```

To load a specific version of `prop-types` replace `15.6.0` with the version number.
To load a specific version of `prop-types` replace `15.6.0` with the version number.

## Usage

Expand All @@ -67,6 +67,7 @@ MyComponent.propTypes = {
// You can declare that a prop is a specific JS primitive. By default, these
// are all optional.
optionalArray: PropTypes.array,
optionalBigInt: PropTypes.bigint,
optionalBool: PropTypes.bool,
optionalFunc: PropTypes.func,
optionalNumber: PropTypes.number,
Expand All @@ -76,11 +77,17 @@ MyComponent.propTypes = {

// Anything that can be rendered: numbers, strings, elements or an array
// (or fragment) containing these types.
// see https://reactjs.org/docs/rendering-elements.html for more info
optionalNode: PropTypes.node,

// A React element.
// A React element (ie. <MyComponent />).
optionalElement: PropTypes.element,

// A React element type (eg. MyComponent).
// a function, string, or "element-like" object (eg. React.Fragment, Suspense, etc.)
// see https://github.com/facebook/react/blob/HEAD/packages/shared/isValidElementType.js
optionalElementType: PropTypes.elementType,

// You can also declare that a prop is an instance of a class. This uses
// JS's instanceof operator.
optionalMessage: PropTypes.instanceOf(Message),
Expand All @@ -102,14 +109,21 @@ MyComponent.propTypes = {
// An object with property values of a certain type
optionalObjectOf: PropTypes.objectOf(PropTypes.number),

// You can chain any of the above with `isRequired` to make sure a warning
// is shown if the prop isn't provided.

// An object taking on a particular shape
optionalObjectWithShape: PropTypes.shape({
color: PropTypes.string,
fontSize: PropTypes.number
optionalProperty: PropTypes.string,
requiredProperty: PropTypes.number.isRequired
}),

// An object with warnings on extra properties
optionalObjectWithStrictShape: PropTypes.exact({
optionalProperty: PropTypes.string,
requiredProperty: PropTypes.number.isRequired
}),

// You can chain any of the above with `isRequired` to make sure a warning
// is shown if the prop isn't provided.
requiredFunc: PropTypes.func.isRequired,

// A value of any data type
Expand Down Expand Up @@ -160,18 +174,18 @@ For example:

```js
"dependencies": {
"prop-types": "^15.5.7"
"prop-types": "^15.5.7"
}
```

For libraries, we *also* recommend leaving it in `dependencies`:

```js
"dependencies": {
"prop-types": "^15.5.7"
"prop-types": "^15.5.7"
},
"peerDependencies": {
"react": "^15.5.0"
"react": "^15.5.0"
}
```

Expand All @@ -185,7 +199,7 @@ For UMD bundles of your components, make sure you **don’t** include `PropTypes

### React 0.14

This package is compatible with **React 0.14.9**. Compared to 0.14.8 (which was released a year ago), there are no other changes in 0.14.9, so it should be a painless upgrade.
This package is compatible with **React 0.14.9**. Compared to 0.14.8 (which was released in March of 2016), there are no other changes in 0.14.9, so it should be a painless upgrade.

```shell
# ATTENTION: Only run this if you still use React 0.14!
Expand Down Expand Up @@ -246,9 +260,11 @@ PropTypes.checkPropTypes(MyComponent.propTypes, props, 'prop', 'MyComponent');
```
See below for more info.

**If you DO want to use validation in production**, you can choose to use the **development version** by importing/requiring `prop-types/prop-types` instead of `prop-types`.

**You might also see this error** if you’re calling a `PropTypes` validator from your own custom `PropTypes` validator. In this case, the fix is to make sure that you are passing *all* of the arguments to the inner function. There is a more in-depth explanation of how to fix it [on this page](https://facebook.github.io/react/warnings/dont-call-proptypes.html#fixing-the-false-positive-in-third-party-proptypes). Alternatively, you can temporarily keep using `React.PropTypes` until React 16, as it would still only warn in this case.

If you use a bundler like Browserify or Webpack, don’t forget to [follow these instructions](https://facebook.github.io/react/docs/installation.html#development-and-production-versions) to correctly bundle your application in development or production mode. Otherwise you’ll ship unnecessary code to your users.
If you use a bundler like Browserify or Webpack, don’t forget to [follow these instructions](https://reactjs.org/docs/optimizing-performance.html#use-the-production-build) to correctly bundle your application in development or production mode. Otherwise you’ll ship unnecessary code to your users.

## PropTypes.checkPropTypes

Expand Down Expand Up @@ -276,3 +292,11 @@ PropTypes.checkPropTypes(myPropTypes, props, 'prop', 'MyComponent');
// Warning: Failed prop type: Invalid prop `age` of type `string` supplied to
// `MyComponent`, expected `number`.
```

## PropTypes.resetWarningCache()

`PropTypes.checkPropTypes(...)` only `console.error`s a given message once. To reset the error warning cache in tests, call `PropTypes.resetWarningCache()`

### License

prop-types is [MIT licensed](./LICENSE).
Loading

0 comments on commit 5e1e5e2

Please sign in to comment.