Skip to content

Commit e37b37d

Browse files
authored
Merge pull request #121 from mohshbool/warnings/dont-call-prototypes
translated warnings/dont-call-proptypes
2 parents 83b25d9 + 46bc192 commit e37b37d

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

โ€Žcontent/warnings/dont-call-proptypes.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ layout: single
44
permalink: warnings/dont-call-proptypes.html
55
---
66

7-
> Note:
7+
> ู…ู„ุงุญุธุฉ:
88
>
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).
9+
> ุชู… ุชุฑุญูŠู„ `React.PropTypes` ุฅู„ู‰ ุญุฒู…ุฉ ู…ู†ูุตู„ุฉ ู…ู†ุฐ ู†ุณุฎุฉ React v15.5. ุงู„ุฑุฌุงุก ุงุณุชุฎุฏุงู… [ู…ูƒุชุจุฉ `prop-types`](https://www.npmjs.com/package/prop-types) ุนูˆุถู‹ุง ุนู† ุฐู„ูƒ.
1010
>
11-
>We provide [a codemod script](/blog/2017/04/07/react-v15.5.0.html#migrating-from-react.proptypes) to automate the conversion.
11+
> ู†ุญู† ู†ูˆูุฑ [a codemod script](/blog/2017/04/07/react-v15.5.0.html#migrating-from-react.proptypes) ู„ุฃุชู…ูŽุชูŽุช ุงู„ุชุญูˆูŠู„.
1212
13-
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.
13+
ููŠ ุฅุตุฏุงุฑ ุฑุฆูŠุณูŠ ู…ุณุชู‚ุจู„ูŠ ู…ู† React ุŒ ุณูŠุชู… ุฅุฒุงู„ุฉ ุงู„ุดูŠูุฑุฉ ุงู„ุชูŠ ุชุทุจู‚ ุฏูˆุงู„ ุงู„ุชุญู‚ู‚ ู…ู† ุงู†ูˆุงุน ุงู„ุฎูˆุงุต ููŠ ู†ูุณุฎุฉ ุงู„ุฅู†ุชุงุฌ. ุนู†ุฏ ุญุฏูˆุซ ุฐู„ูƒ ุŒ ุฃูŠ ุดูŠูุฑุฉ ุชุณุชุฏุนูŠ ู‡ุฐู‡ ุงู„ุฏูˆุงู„ -ุงู„ุชูŠ ู„ู… ูŠุชู… ุฅุฒุงู„ุชู‡ุง ููŠ ู†ุณุฎุฉ ุงู„ุฅู†ุชุงุฌ- ูŠุฏูˆูŠู‹ุง ุณูŠูุญุฏุซ "ูŠูู„ู‚ูŠ" ุฎุทุฃ.
1414

15-
### Declaring PropTypes is still fine {#declaring-proptypes-is-still-fine}
15+
### ู„ุง ุจุฃุณ ุจุชุตุฑูŠุญ PropTypes {#declaring-proptypes-is-still-fine}
1616

17-
The normal usage of PropTypes is still supported:
17+
ุงุณุชุฎุฏุงู… PropTypes ุงู„ุฅุนุชูŠุงุฏูŠ ู…ุง ุฒุงู„ ู…ุฏุนูˆู…ู‹ุง:
1818

1919
```javascript
2020
Button.propTypes = {
2121
highlighted: PropTypes.bool
2222
};
2323
```
2424

25-
Nothing changes here.
25+
ู„ุง ุชุบูŠู‘ุฑุงุช ู‡ู†ุง.
2626

27-
### Donโ€™t call PropTypes directly {#dont-call-proptypes-directly}
27+
### ู„ุง ุชุณุชุฏุนูŠ PropTypes ู…ุจุงุดุฑุฉ {#dont-call-proptypes-directly}
2828

29-
Using PropTypes in any other way than annotating React components with them is no longer supported:
29+
ุงุณุชุฎุฏุงู… PropTypes ุจุฃูŠ ุทุฑูŠู‚ุฉ ุฃูุฎุฑู‰ ุบูŠุฑ ุชุนู„ูŠู‚ู‡ุง ุจู…ููƒูˆู‘ู† React ู„ู… ูŠูŽุนูุฏ ู…ุฏุนูˆู…ู‹ุง:
3030

3131
```javascript
3232
var apiShape = PropTypes.shape({
@@ -38,13 +38,13 @@ var apiShape = PropTypes.shape({
3838
var error = apiShape(json, 'response');
3939
```
4040

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).
41+
ุฅู† ูƒูู†ุชูŽ ุชูŽุนุชูŽู…ูุฏ ุนู„ู‰ ุงุณุชุฎุฏุงู… PropTypes ุจู‡ุฐู‡ ุงู„ุทุฑูŠู‚ุฉ ุŒ ูู†ุญู†ู ู†ูุดูŽุฌูู‘ุน ุนู„ู‰ ุงุณุชุฎุฏุงู… ุงูˆ ุนู…ู„ ู†ุณุฎุฉ "fork" ู…ู† PropTypes ู…ุซู„ [ู‡ุงุชูŠู†](https://github.com/aackerman/PropTypes) [ุงู„ุญุฒู…ุชูŠู†](https://github.com/developit/proptypes).
4242

43-
If you don't fix the warning, this code will crash in production with React 16.
43+
ุงู† ู„ู… ุชูุตู„ูุญ ุงู„ุชุญุฐูŠุฑ ูุฃู† ู‡ุฐู‡ ุงู„ุดูŠูุฑุฉ ุณุชู†ู‡ุงุฑ "crash" ููŠ ู†ุณุฎุฉ ุงู„ุฅุตุฏุงุฑ ู…ุน React 16.
4444

45-
### If you don't call PropTypes directly but still get the warning {#if-you-dont-call-proptypes-directly-but-still-get-the-warning}
45+
### ุงู† ูƒู†ุช ู„ุง ุชูŽุณุชูŽุฏุนูŠ PropTypes ู…ูุจุงุดุฑุฉ ูˆู„ูƒู† ุงู„ุชุญุฐูŠุฑ ู„ุง ุฒุงู„ ูŠุธู‡ุฑ {#if-you-dont-call-proptypes-directly-but-still-get-the-warning}
4646

47-
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:
47+
ุงุณุชุนุฑุถ ุฑูŽุตู‘ุฉ "stack" ุงู„ู…ูู†ุชูŽุฌ ู…ู† ู‡ุฐู‡ ุงู„ุชุญุฐูŠุฑ. ุนู†ุฏ ุงู„ู‚ูŠุงู… ุจุฐู„ูƒ ุŒ ุณุชุฌุฏ ุชุนุฑูŠู ุงู„ู…ููƒูˆู† ุงู„ู…ุณุคู„ ุนู† ุงุณุชุฏุนุงุก PropTypes ุงู„ู…ูุจุงุดุฑ. ู…ู† ุงู„ู…ูุฑูŽุฌูŽู‘ุญ ุงู† ุงู„ู…ูุดูƒู„ุฉ ุชูุนุฒู‰ ุงู„ู‰ PropTypes ุงู„ุทุฑู ุงู„ุซุงู„ุซ "third-party" ุงู„ุชูŠ ุชูุบูŽู„ูู‘ู PropTypes ู…ู† React. ู…ุซู„ู‹ุง:
4848

4949
```js
5050
Button.propTypes = {
@@ -55,13 +55,13 @@ Button.propTypes = {
5555
}
5656
```
5757

58-
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.
58+
ููŠ ู‡ุฐู‡ ุงู„ุญุงู„ุฉ ุŒ `ThirdPartyPropTypes.deprecated` ู…ูุบูŽู„ู‘ูู "wrapper" ูŠุณุชุฏุนูŠ `PropTypes.bool`. ู„ุง ุจุฃุณ ุจู‡ุฐุง ุงู„ู†ู…ุท ู„ูˆุญุฏู‡ ูˆู„ูƒู†ู‡ ูŠูุทู„ู‚ ุฅูŠุฌุงุจูŠุฉ ุฒุงุฆูุฉ "false positive" ู„ุฃู† React ุชุนุชู‚ุฏ ุงู†ูƒ ุชุณุชุฏุนูŠ PropTypes ู…ูุจุงุดุฑุฉ. ุงู„ู…ูŽู‚ุทุน ุงู„ุชุงู„ูŠ ุณูŠุดุฑุญ ูƒูŠููŠุฉ ุฅุตู„ุงุญ ู‡ุฐู‡ ุงู„ู…ูุดูƒูู„ุฉ ู„ูู…ูŽูƒุชุจุฉ ุชูุทูŽุจูู‚ ุดูŠุฆู‹ุง ู…ูุซู„ `ThirdPartyPropTypes`. ุฅู† ู„ูŽู… ุชูŽูƒูู† ู…ูุคูŽู„ูู‘ู ุงู„ู…ูƒุชุจุฉ ูŠูู…ูƒูู†ููƒูŽ ุชู‚ุฏูŠู… ุทู„ุจ ู…ูุดูƒู„ุฉ "issue" ุถุฏู‡ุง.
5959

60-
### Fixing the false positive in third party PropTypes {#fixing-the-false-positive-in-third-party-proptypes}
60+
### ุฅุตู„ุงุญ ุงู„ุฅูŠุฌุงุจูŠู‘ุฉ ุงู„ุฒุงุฆูุฉ ููŠ PropTypes ุงู„ุทุฑู ุงู„ุซุงู„ุซ {#fixing-the-false-positive-in-third-party-proptypes}
6161

62-
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.
62+
ุฅู† ูƒูู†ุช ู…ูุคูŽู„ูู‘ู ู…ูƒุชุจุฉ PropTypes ุทุฑู ุซุงู„ุซ ูˆ ูƒู†ุช ุชุณู…ุญ ู„ู„ู…ูุณุชูŽุฎุฏู…ูŠู† ุจูุชูŽุบู„ูŠู PropTypes ู…ู† React ุงู„ู…ูˆุฌูˆุฏุฉ ุŒ ูู‚ุฏ ูŠูŽุฑูˆู† ู‡ุฐุง ุงู„ุชุญุฐูŠุฑ ุขุชูŠู‹ุง ู…ู† ุงู„ู…ูƒุชุจุฉ ุฎุงุตุชูƒ. ูŠูŽุญูุฏุซ ู‡ุฐุง ู„ุฃู† React ู„ุง ุชูŽุฑู‰ ุงู„ูˆุณูŠุท "argument" ุงู„ุฃุฎูŠุฑ "ุณุฑูŠู‘ secret" [ุงู„ุชูŠ ุชูู…ูŽุฑูุฑู‡](https://github.com/facebook/react/pull/7132) ู„ูุฑูŽุตุฏ ุงุณุชุฏุนุงุฆุงุช PropTypes ุงู„ูŠุฏูˆูŠุฉ.
6363

64-
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:
64+
ุฅู„ูŠูƒ ูƒูŠููŠุฉ ุฅุตู„ุงุญู‡. ุณูˆู ู†ูŽุณุชูŽุฎุฏูู… `deprecated` ู…ู† [react-bootstrap/react-prop-types](https://github.com/react-bootstrap/react-prop-types/blob/0d1cd3a49a93e513325e3258b28a82ce7d38e690/src/deprecated.js) ูƒู…ุซุงู„. ุงู„ุชุทุจูŠู‚ ุงู„ุญุงู„ูŠ ูŠูู…ูŽุฑูุฑ ูˆุณุงุฆุท `props` ูˆ `propName` ูˆ `componentName` ูู‚ุท:
6565

6666
```javascript
6767
export default function deprecated(propType, explanation) {
@@ -79,7 +79,7 @@ export default function deprecated(propType, explanation) {
7979
}
8080
```
8181

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:
82+
ู„ุฅุตู„ุงุญ ุงู„ุฅูŠุฌุงุจูŠุฉ ุงู„ุณู„ุจูŠุฉ ุชุฃูƒู‘ูŽุฏ ู…ู† ุชู…ุฑูŠุฑ **ุฌู…ูŠุน** ุงู„ูˆุณุงุฆุท ุงู„ู‰ PropTypes ุงู„ู…ูุบูŽู„ู‘ูŽู. ูŠูŽุณู‡ูู„ ุงู„ู‚ูŠุงู… ุจู‡ุฐุง ุนู† ุทุฑูŠู‚ ุตูŠุบุฉ `...rest` ู…ู† ES6:
8383

8484
```javascript
8585
export default function deprecated(propType, explanation) {
@@ -97,4 +97,4 @@ export default function deprecated(propType, explanation) {
9797
}
9898
```
9999

100-
This will silence the warning.
100+
ุณูŽูŠูุตู…ูุช ุฐู„ูƒ ุงู„ุชุญุฐูŠุฑ.

0 commit comments

Comments
ย (0)