Amend documentation for skipping useEffect
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- JavaScript
- Estrelas
- 11.8k
- Forks
- 7.9k
- Merge médio
- 1d 11h
- PRs com merge (30d)
- 11
Descrição
This is a documentation improvement request.
Currently https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects explains skipping a useEffect based on a state variable by showing the following code:
useEffect(() => {
document.title = `You clicked ${count} times`;
}, [count]); // Only re-run the effect if count changes
With the following explanation:
In the example above, we pass [count] as the second argument. What does this mean? If the count is 5, and then our component re-renders with count still equal to 5, React will compare [5] from the previous render and [5] from the next render. Because all items in the array are the same (5 === 5), React would skip the effect. That’s our optimization.
However, as the array we're shown only has a single element it, it is ambiguous what "all the items in the array" means. E.g. we cannot tell whether that's intentional phrasing, or just "plain English" that isn't actually tied to any technical precision.
Could this phrasing either be made more explicit, or (ideally) can an extra paragraph be added to explain what happens to an array with more than one element?
(originally filed as from https://github.com/facebook/react/issues/15068)
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pela seção “Tip: Optimizing Performance by Skipping Effects” de docs/hooks-effect.html, vinculada na issue. Revise a explicação do array de dependências [count] e esclareça como as comparações funcionam quando um array tem vários elementos. Considera-se concluído quando a documentação explicar explicitamente e sem ambiguidade o caso de vários elementos.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- javascript, react
- Domínio
- documentation
- Tipo de issue
- Documentação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 55/100