-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translate page dont-call-proptypes.md #19
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,62 +6,62 @@ permalink: warnings/dont-call-proptypes.html | |||||
|
||||||
> Note: | ||||||
> | ||||||
> `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). | ||||||
> `React.PropTypes` foi movido para um pacote diferente desde a versão v15.5. do React. Por favor, use [the `prop-types` library agora](https://www.npmjs.com/package/prop-types). | ||||||
> | ||||||
>We provide [a codemod script](/blog/2017/04/07/react-v15.5.0.html#migrating-from-react.proptypes) to automate the conversion. | ||||||
>Nós fornecemos [um script de migração](/blog/2017/04/07/react-v15.5.0.html#migrating-from-react.proptypes) para automatizar o processo. | ||||||
|
||||||
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. | ||||||
Em releases futuras do React, o código que implementa a validação de PropType será removida. Uma vez isso acontecendo, qualquer código que contenha essas funções chamadas de forma manual irão emitir um erro. | ||||||
|
||||||
### Declaring PropTypes is still fine {#declaring-proptypes-is-still-fine} | ||||||
### Declarar PropTypes ainda é uma boa ideia {#declaring-proptypes-is-still-fine} | ||||||
|
||||||
The normal usage of PropTypes is still supported: | ||||||
A forma normal de usar a PropTypes ainda é suportada: | ||||||
|
||||||
```javascript | ||||||
Button.propTypes = { | ||||||
highlighted: PropTypes.bool | ||||||
}; | ||||||
``` | ||||||
|
||||||
Nothing changes here. | ||||||
Nada mudou por aqui. | ||||||
|
||||||
### Don’t call PropTypes directly {#dont-call-proptypes-directly} | ||||||
### Não chame PropTypes diretamente {#dont-call-proptypes-directly} | ||||||
|
||||||
Using PropTypes in any other way than annotating React components with them is no longer supported: | ||||||
Usar PropTypes de uma forma diferente que não seja a anotação dos componentes React não é mais suportado: | ||||||
|
||||||
```javascript | ||||||
var apiShape = PropTypes.shape({ | ||||||
body: PropTypes.object, | ||||||
statusCode: PropTypes.number.isRequired | ||||||
}).isRequired; | ||||||
|
||||||
// Not supported! | ||||||
// Não suportado | ||||||
var error = apiShape(json, 'response'); | ||||||
``` | ||||||
|
||||||
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). | ||||||
Caso você dependa do uso PropTypes dessa forma, encorajamos você a usar ou criar um fork da PropTypes (como [esses](https://github.com/aackerman/PropTypes) [dois](https://github.com/developit/proptypes) pacotes). | ||||||
|
||||||
If you don't fix the warning, this code will crash in production with React 16. | ||||||
Se você não corrigir esse alerta, esse código não funcionará em produção com o React 16. | ||||||
|
||||||
### If you don't call PropTypes directly but still get the warning {#if-you-dont-call-proptypes-directly-but-still-get-the-warning} | ||||||
### Se você não chama PropTypes diretamente mas mesmo assim recebe esse alerta {#if-you-dont-call-proptypes-directly-but-still-get-the-warning} | ||||||
|
||||||
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: | ||||||
Inspecione a stack trace produzida pelo alerta. Você encontrará a definição do componente responsável pela chamada direta da PropTypes. Provavelmente, o problema é causado por uma PropTypes de terceiros que encapsula a PropTypes do React, por exemplo: | ||||||
|
||||||
```js | ||||||
Button.propTypes = { | ||||||
highlighted: ThirdPartyPropTypes.deprecated( | ||||||
PropTypes.bool, | ||||||
'Use `active` prop instead' | ||||||
'Use `active` prop ao invés disso' | ||||||
) | ||||||
} | ||||||
``` | ||||||
|
||||||
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. | ||||||
Nesse caso, `ThirdPartyPropTypes.deprecated` é um wrapper chamando `PropTypes.bool`. Esse padrão por si só já é o suficiente, mas dispara um falso positivo pelo fato do React pensar que está chamando diretamente a PropTypes. No próximo tópico, iremos explicar como resolver esse problema para a implementação de uma biblioteca, algo como `ThirdPartyPropTypes`. Caso não seja uma biblioteca que você escreveu, você pode abrir um issue por isso. | ||||||
|
||||||
### Fixing the false positive in third party PropTypes {#fixing-the-false-positive-in-third-party-proptypes} | ||||||
### Resolvendo o falso positivo em uma PropTypes de terceiro {#fixing-the-false-positive-in-third-party-proptypes} | ||||||
|
||||||
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. | ||||||
Se você é o autor de uma biblioteca terceira com PropTypes e permite que seus usuários façam wrap de uma React PropTypes existente, provavelmente eles começarão a receber esse warning da sua biblioteca. Isso acontece porque o React não enxerga um último parâmetro "secreto" que passa a [detectar](https://github.com/facebook/react/pull/7132) manualmente as chamadas da PropTypes. | ||||||
cezaraugusto marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
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: | ||||||
Aqui está como corrigir isso. Usaremos `deprecated` daqui [react-bootstrap/react-prop-types](https://github.com/react-bootstrap/react-prop-types/blob/0d1cd3a49a93e513325e3258b28a82ce7d38e690/src/deprecated.js) como exemplo. A atual implementação só passa adiante as `props`, `propName`, and `componentName` arguments: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```javascript | ||||||
export default function deprecated(propType, explanation) { | ||||||
|
@@ -79,7 +79,7 @@ export default function deprecated(propType, explanation) { | |||||
} | ||||||
``` | ||||||
|
||||||
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: | ||||||
Para resolver o falso positivo, tenha certeza que está passando **todos** os parâmetro para o wrapped da PropType. Um jeito fácil de fazer isso com ES6 é usando a notação `...rest`: | ||||||
|
||||||
```javascript | ||||||
export default function deprecated(propType, explanation) { | ||||||
|
@@ -97,4 +97,4 @@ export default function deprecated(propType, explanation) { | |||||
} | ||||||
``` | ||||||
|
||||||
This will silence the warning. | ||||||
Isso fará com que o warning pare de ser lançado. | ||||||
cezaraugusto marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acho a modificação de "[...], mas [...]" para "[...]. Mas, [...]" errada neste caso.