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
> `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.
Using PropTypes in any other way than annotating React components with them is no longer supported:
29
+
除了用于解释 React 组件,其他使用 PropTypes 的方式将不再受到支持:
30
30
31
31
```javascript
32
32
var apiShape =PropTypes.shape({
33
33
body:PropTypes.object,
34
34
statusCode:PropTypes.number.isRequired
35
35
}).isRequired;
36
36
37
-
//Not supported!
37
+
//不支持!
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,11 +79,11 @@ 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