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: src/content/reference/eslint-plugin-react-hooks/lints/static-components.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,30 +4,30 @@ title: static-components
4
4
5
5
<Intro>
6
6
7
-
Validates that components are static, not recreated every render. Components that are recreated dynamically can reset state and trigger excessive re-rendering.
7
+
Valida que os componentes são estáticos, não recriados a cada renderização. Componentes que são recriados dinamicamente podem redefinir o estado e acionar renderizações excessivas.
8
8
9
9
</Intro>
10
10
11
-
## Rule Details {/*rule-details*/}
11
+
## Detalhes da Regra {/*rule-details*/}
12
12
13
-
Components defined inside other components are recreated on every render. React sees each as a brand new component type, unmounting the old one and mounting the new one, destroying all state and DOM nodes in the process.
13
+
Componentes definidos dentro de outros componentes são recriados a cada renderização. O React os vê como um tipo de componente totalmente novo, desinstalando o antigo e instalando o novo, destruindo todo o estado e nós do DOM no processo.
14
14
15
-
### Invalid {/*invalid*/}
15
+
### Inválido {/*invalid*/}
16
16
17
-
Examples of incorrect code for this rule:
17
+
Exemplos de código incorreto para esta regra:
18
18
19
19
```js
20
-
// ❌ Component defined inside component
20
+
// ❌ Componente definido dentro de outro componente
21
21
functionParent() {
22
-
constChildComponent= () => { //New component every render!
22
+
constChildComponent= () => { //Novo componente a cada renderização!
### I need to render different components conditionally {/*conditional-components*/}
60
+
### Preciso renderizar componentes diferentes condicionalmente {/*conditional-components*/}
61
61
62
-
You might define components inside to access local state:
62
+
Você pode definir componentes dentro de outros para acessar o estado local:
63
63
64
64
```js {expectedErrors: {'react-compiler': [13]}}
65
-
// ❌ Wrong: Inner component to access parent state
65
+
// ❌ Errado: Componente interno para acessar o estado do pai
66
66
functionParent() {
67
67
const [theme, setTheme] =useState('light');
68
68
69
-
functionThemedButton() { //Recreated every render!
69
+
functionThemedButton() { //Recriado a cada renderização!
70
70
return (
71
71
<button className={theme}>
72
72
Click me
@@ -78,10 +78,10 @@ function Parent() {
78
78
}
79
79
```
80
80
81
-
Pass data as props instead:
81
+
Passe os dados como props em vez disso:
82
82
83
83
```js
84
-
// ✅ Better: Pass props to static component
84
+
// ✅ Melhor: Passe props para componente estático
85
85
functionThemedButton({theme}) {
86
86
return (
87
87
<button className={theme}>
@@ -98,6 +98,6 @@ function Parent() {
98
98
99
99
<Note>
100
100
101
-
If you find yourself wanting to define components inside other components to access local variables, that's a sign you should be passing props instead. This makes components more reusable and testable.
101
+
Se você se encontrar querendo definir componentes dentro de outros componentes para acessar variáveis locais, isso é um sinal de que você deveria estar passando props em vez disso. Isso torna os componentes mais reutilizáveis e testáveis.
0 commit comments