You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/warnings/dont-call-proptypes.md
+19-19Lines changed: 19 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -4,29 +4,29 @@ layout: single
4
4
permalink: warnings/dont-call-proptypes.html
5
5
---
6
6
7
-
> Note:
7
+
> ู ูุงุญุธุฉ:
8
8
>
9
-
> `React.PropTypes`has moved into a different package since React v15.5. Please use [the`prop-types` library instead](https://www.npmjs.com/package/prop-types).
In a future major release of React, the code that implements PropType validation functions will be stripped in production. Once this happens, any code that calls these functions manually (that isn't stripped in production) will throw an error.
@@ -38,13 +38,13 @@ var apiShape = PropTypes.shape({
38
38
var error =apiShape(json, 'response');
39
39
```
40
40
41
-
If you depend on using PropTypes like this, we encourage you to use or create a fork of PropTypes (such as [these](https://github.com/aackerman/PropTypes)[two](https://github.com/developit/proptypes) packages).
Inspect the stack trace produced by the warning. You will find the component definition responsible for the PropTypes direct call. Most likely, the issue is due to third-party PropTypes that wrap Reactโs PropTypes, for example:
In this case, `ThirdPartyPropTypes.deprecated`is a wrapper calling`PropTypes.bool`. This pattern by itself is fine, but triggers a false positive because React thinks you are calling PropTypes directly. The next section explains how to fix this problem for a library implementing something like `ThirdPartyPropTypes`. If it's not a library you wrote, you can file an issue against it.
If you are an author of a third party PropTypes library and you let consumers wrap existing React PropTypes, they might start seeing this warning coming from your library. This happens because React doesn't see a "secret" last argument that [it passes](https://github.com/facebook/react/pull/7132)to detect manual PropTypes calls.
Here is how to fix it. We will use `deprecated`from[react-bootstrap/react-prop-types](https://github.com/react-bootstrap/react-prop-types/blob/0d1cd3a49a93e513325e3258b28a82ce7d38e690/src/deprecated.js)as an example. The current implementation only passes down the `props`, `propName`, and`componentName`arguments:
@@ -79,7 +79,7 @@ export default function deprecated(propType, explanation) {
79
79
}
80
80
```
81
81
82
-
In order to fix the false positive, make sure you pass **all**arguments down to the wrapped PropType. This is easy to do with the ES6 `...rest`notation:
0 commit comments