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/use-memo.md
+25-25Lines changed: 25 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,36 +4,36 @@ title: use-memo
4
4
5
5
<Intro>
6
6
7
-
Validates that the `useMemo`hook is used with a return value. See [`useMemo` docs](/reference/react/useMemo)for more information.
7
+
Valida que o hook `useMemo`é usado com um valor de retorno. Veja a [documentação do `useMemo`](/reference/react/useMemo)para mais informações.
8
8
9
9
</Intro>
10
10
11
-
## Rule Details {/*rule-details*/}
11
+
## Detalhes da Regra {/*rule-details*/}
12
12
13
-
`useMemo`is for computing and caching expensive values, not for side effects. Without a return value, `useMemo`returns`undefined`, which defeats its purpose and likely indicates you're using the wrong hook.
13
+
`useMemo`serve para computar e cachear valores custosos, não para efeitos colaterais. Sem um valor de retorno, `useMemo`retorna`undefined`, o que frustra seu propósito e provavelmente indica que você está usando o hook errado.
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': [3]}}
20
-
// ❌ No return value
20
+
// ❌ Sem valor de retorno
21
21
functionComponent({ data }) {
22
22
constprocessed=useMemo(() => {
23
23
data.forEach(item=>console.log(item));
24
-
//Missing return!
24
+
//Falta o retorno!
25
25
}, [data]);
26
26
27
-
return<div>{processed}</div>; //Always undefined
27
+
return<div>{processed}</div>; //Sempre undefined
28
28
}
29
29
```
30
30
31
-
### Valid {/*valid*/}
31
+
### Válido {/*valid*/}
32
32
33
-
Examples of correct code for this rule:
33
+
Exemplos de código correto para esta regra:
34
34
35
35
```js
36
-
// ✅ Returns computed value
36
+
// ✅ Retorna valor computado
37
37
functionComponent({ data }) {
38
38
constprocessed=useMemo(() => {
39
39
returndata.map(item=> item *2);
@@ -43,52 +43,52 @@ function Component({ data }) {
43
43
}
44
44
```
45
45
46
-
## Troubleshooting {/*troubleshooting*/}
46
+
## Solução de Problemas {/*troubleshooting*/}
47
47
48
-
### I need to run side effects when dependencies change {/*side-effects*/}
48
+
### Preciso executar efeitos colaterais quando as dependências mudam {/*side-effects*/}
49
49
50
-
You might try to use `useMemo`for side effects:
50
+
Você pode tentar usar `useMemo`para efeitos colaterais:
51
51
52
52
{/* TODO(@poteto) fix compiler validation to check for unassigned useMemos */}
0 commit comments