Skip to content

Commit 5de06f8

Browse files
docs: translate incompatible-library.md to Português (Brasil) (#1217)
Co-authored-by: translate-react-bot[bot] <251169733+translate-react-bot[bot]@users.noreply.github.com>
1 parent d255293 commit 5de06f8

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

src/content/reference/eslint-plugin-react-hooks/lints/incompatible-library.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,59 @@ title: incompatible-library
44

55
<Intro>
66

7-
Validates against usage of libraries which are incompatible with memoization (manual or automatic).
7+
Valida contra o uso de bibliotecas que são incompatíveis com a memoização (manual ou automática).
88

99
</Intro>
1010

1111
<Note>
1212

13-
These libraries were designed before React's memoization rules were fully documented. They made the correct choices at the time to optimize for ergonomic ways to keep components just the right amount of reactive as app state changes. While these legacy patterns worked, we have since discovered that it's incompatible with React's programming model. We will continue working with library authors to migrate these libraries to use patterns that follow the Rules of React.
13+
Essas bibliotecas foram projetadas antes que as regras de memoização do React fossem totalmente documentadas. Elas fizeram as escolhas corretas na época para otimizar maneiras ergonômicas de manter os componentes reativos na medida certa conforme o estado do aplicativo muda. Embora esses padrões legados funcionassem, descobrimos desde então que eles são incompatíveis com o modelo de programação do React. Continuaremos trabalhando com os autores das bibliotecas para migrar essas bibliotecas para usar padrões que sigam as Regras do React.
1414

1515
</Note>
1616

17-
## Rule Details {/*rule-details*/}
17+
## Detalhes da Regra {/*rule-details*/}
1818

19-
Some libraries use patterns that aren't supported by React. When the linter detects usages of these APIs from a [known list](https://github.com/facebook/react/blob/main/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts), it flags them under this rule. This means that React Compiler can automatically skip over components that use these incompatible APIs, in order to avoid breaking your app.
19+
Algumas bibliotecas usam padrões que não são suportados pelo React. Quando o linter detecta usos dessas APIs de uma [lista conhecida](https://github.com/facebook/react/blob/main/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts), ele as sinaliza sob esta regra. Isso significa que o Compilador React pode pular automaticamente componentes que usam essas APIs incompatíveis, a fim de evitar a quebra do seu aplicativo.
2020

2121
```js
22-
// Example of how memoization breaks with these libraries
22+
// Exemplo de como a memoização quebra com essas bibliotecas
2323
function Form() {
2424
const { watch } = useForm();
2525

26-
//This value will never update, even when 'name' field changes
26+
//Este valor nunca será atualizado, mesmo quando o campo 'name' mudar
2727
const name = useMemo(() => watch('name'), [watch]);
2828

29-
return <div>Name: {name}</div>; // UI appears "frozen"
29+
return <div>Name: {name}</div>; // A UI parece "congelada"
3030
}
3131
```
3232

33-
React Compiler automatically memoizes values following the Rules of React. If something breaks with manual `useMemo`, it will also break the compiler's automatic optimization. This rule helps identify these problematic patterns.
33+
O Compilador React memoiza automaticamente valores seguindo as Regras do React. Se algo quebrar com `useMemo` manual, também quebrará a otimização automática do compilador. Esta regra ajuda a identificar esses padrões problemáticos.
3434

3535
<DeepDive>
3636

37-
#### Designing APIs that follow the Rules of React {/*designing-apis-that-follow-the-rules-of-react*/}
37+
#### Projetando APIs que seguem as Regras do React {/*designing-apis-that-follow-the-rules-of-react*/}
3838

39-
One question to think about when designing a library API or hook is whether calling the API can be safely memoized with `useMemo`. If it can't, then both manual and React Compiler memoizations will break your user's code.
39+
Uma pergunta a se considerar ao projetar uma API ou hook de biblioteca é se a chamada da API pode ser memoizada com segurança com `useMemo`. Se não puder, tanto a memoização manual quanto a do Compilador React quebrarão o código do seu usuário.
4040

41-
For example, one such incompatible pattern is "interior mutability". Interior mutability is when an object or function keeps its own hidden state that changes over time, even though the reference to it stays the same. Think of it like a box that looks the same on the outside but secretly rearranges its contents. React can't tell anything changed because it only checks if you gave it a different box, not what's inside. This breaks memoization, since React relies on the outer object (or function) changing if part of its value has changed.
41+
Por exemplo, um desses padrões incompatíveis é a "mutabilidade interior". Mutabilidade interior é quando um objeto ou função mantém seu próprio estado oculto que muda ao longo do tempo, mesmo que a referência a ele permaneça a mesma. Pense nisso como uma caixa que parece a mesma por fora, mas secretamente reorganiza seu conteúdo. O React não consegue dizer que algo mudou porque ele apenas verifica se você deu a ele uma caixa diferente, não o que está dentro. Isso quebra a memoização, pois o React depende do objeto (ou função) externo mudar se parte de seu valor mudou.
4242

43-
As a rule of thumb, when designing React APIs, think about whether `useMemo` would break it:
43+
Como regra geral, ao projetar APIs React, pense se `useMemo` a quebraria:
4444

4545
```js
4646
function Component() {
4747
const { someFunction } = useLibrary();
48-
// it should always be safe to memoize functions like this
48+
// deve ser sempre seguro memoizar funções como esta
4949
const result = useMemo(() => someFunction(), [someFunction]);
5050
}
5151
```
5252

53-
Instead, design APIs that return immutable state and use explicit update functions:
53+
Em vez disso, projete APIs que retornem estado imutável e usem funções de atualização explícitas:
5454

5555
```js
56-
//Good: Return immutable state that changes reference when updated
56+
//Bom: Retorna estado imutável que muda de referência quando atualizado
5757
function Component() {
5858
const { field, updateField } = useLibrary();
59-
// this is always safe to memo
59+
// isso é sempre seguro para memoizar
6060
const greeting = useMemo(() => `Hello, ${field.name}!`, [field.name]);
6161

6262
return (
@@ -73,26 +73,26 @@ function Component() {
7373

7474
</DeepDive>
7575

76-
### Invalid {/*invalid*/}
76+
### Inválido {/*invalid*/}
7777

78-
Examples of incorrect code for this rule:
78+
Exemplos de código incorreto para esta regra:
7979

8080
```js
81-
// ❌ react-hook-form `watch`
81+
//`watch` do react-hook-form
8282
function Component() {
8383
const {watch} = useForm();
84-
const value = watch('field'); // Interior mutability
84+
const value = watch('field'); // Mutabilidade interior
8585
return <div>{value}</div>;
8686
}
8787

88-
//TanStack Table `useReactTable`
88+
// ❌ `useReactTable` da TanStack Table
8989
function Component({data}) {
9090
const table = useReactTable({
9191
data,
9292
columns,
9393
getCoreRowModel: getCoreRowModel(),
9494
});
95-
// table instance uses interior mutability
95+
// a instância da tabela usa mutabilidade interior
9696
return <Table table={table} />;
9797
}
9898
```
@@ -101,10 +101,10 @@ function Component({data}) {
101101

102102
#### MobX {/*mobx*/}
103103

104-
MobX patterns like `observer` also break memoization assumptions, but the linter does not yet detect them. If you rely on MobX and find that your app doesn't work with React Compiler, you may need to use the `"use no memo" directive`.
104+
Padrões MobX como `observer` também quebram as suposições de memoização, mas o linter ainda não os detecta. Se você depende do MobX e descobre que seu aplicativo não funciona com o Compilador React, pode ser necessário usar a diretiva `"use no memo"`.
105105

106106
```js
107-
//MobX `observer`
107+
// ❌ `observer` do MobX
108108
const Component = observer(() => {
109109
const [timer] = useState(() => new Timer());
110110
return <span>Seconds passed: {timer.secondsPassed}</span>;
@@ -113,12 +113,12 @@ const Component = observer(() => {
113113

114114
</Pitfall>
115115

116-
### Valid {/*valid*/}
116+
### Válido {/*valid*/}
117117

118-
Examples of correct code for this rule:
118+
Exemplos de código correto para esta regra:
119119

120120
```js
121-
//For react-hook-form, use `useWatch`:
121+
//Para react-hook-form, use `useWatch`:
122122
function Component() {
123123
const {register, control} = useForm();
124124
const watchedValue = useWatch({
@@ -135,4 +135,4 @@ function Component() {
135135
}
136136
```
137137

138-
Some other libraries do not yet have alternative APIs that are compatible with React's memoization model. If the linter doesn't automatically skip over your components or hooks that call these APIs, please [file an issue](https://github.com/facebook/react/issues) so we can add it to the linter.
138+
Algumas outras bibliotecas ainda não possuem APIs alternativas que sejam compatíveis com o modelo de memoização do React. Se o linter não pular automaticamente seus componentes ou hooks que chamam essas APIs, por favor, [abra uma issue](https://github.com/facebook/react/issues) para que possamos adicioná-la ao linter.

0 commit comments

Comments
 (0)