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
{{ message }}
Repository navigation
Commit 05d1dd4
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/content/reference/eslint-plugin-react-hooks/lints/component-hook-factories.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,27 +4,27 @@ title: component-hook-factories
4
4
5
5
<Intro>
6
6
7
-
Validates against higher order functions defining nested components or hooks. Components and hooks should be defined at the module level.
7
+
Valida contra funções de ordem superior que definem componentes ou hooks aninhados. Componentes e hooks devem ser definidos no nível do módulo.
8
8
9
9
</Intro>
10
10
11
-
## Rule Details {/*rule-details*/}
11
+
## Detalhes da Regra {/*rule-details*/}
12
12
13
-
Defining components or hooks inside other functions creates new instances on every call. React treats each as a completely different component, destroying and recreating the entire component tree, losing all state, and causing performance problems.
13
+
Definir componentes ou hooks dentro de outras funções cria novas instâncias a cada chamada. O React trata cada uma como um componente completamente diferente, destruindo e recriando toda a árvore de componentes, perdendo todo o estado e causando problemas de desempenho.
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 {expectedErrors: {'react-compiler': [14]}}
20
-
// ❌ Factory function creating components
20
+
// ❌ Função factory criando componentes
21
21
functioncreateComponent(defaultValue) {
22
22
returnfunctionComponent() {
23
23
// ...
24
24
};
25
25
}
26
26
27
-
// ❌ Component defined inside component
27
+
// ❌ Componente definido dentro de outro componente
28
28
functionParent() {
29
29
functionChild() {
30
30
// ...
@@ -33,38 +33,38 @@ function Parent() {
33
33
return<Child />;
34
34
}
35
35
36
-
// ❌ Hook factory function
36
+
// ❌ Função factory de hook
37
37
functioncreateCustomHook(endpoint) {
38
38
returnfunctionuseData() {
39
39
// ...
40
40
};
41
41
}
42
42
```
43
43
44
-
### Valid {/*valid*/}
44
+
### Válido {/*valid*/}
45
45
46
-
Examples of correct code for this rule:
46
+
Exemplos de código correto para esta regra:
47
47
48
48
```js
49
-
// ✅ Component defined at module level
49
+
// ✅ Componente definido no nível do módulo
50
50
functionComponent({ defaultValue }) {
51
51
// ...
52
52
}
53
53
54
-
// ✅ Custom hook at module level
54
+
// ✅ Hook personalizado no nível do módulo
55
55
functionuseData(endpoint) {
56
56
// ...
57
57
}
58
58
```
59
59
60
-
## Troubleshooting {/*troubleshooting*/}
60
+
## Solução de Problemas {/*troubleshooting*/}
61
61
62
-
### I need dynamic component behavior {/*dynamic-behavior*/}
62
+
### Preciso de comportamento dinâmico no componente {/*dynamic-behavior*/}
63
63
64
-
You might think you need a factory to create customized components:
64
+
Você pode achar que precisa de uma factory para criar componentes personalizados:
0 commit comments