Prefer functional updates version in hooks documentation
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
Currently React hooks documentation at section Updating state is using a counter example for bot hooks and class based components. To recap:
In a class, we need to call this.setState() to update the count state:
<button onClick={() => this.setState({ count: this.state.count + 1 })}>
Click me
</button>
In a function, we already have setCount and count as variables so we don’t need this:
<button onClick={() => setCount(count + 1)}>
Click me
</button>
Although I can understand than this documentation must be simple and this example is really straightforward, isn't this a bad patter? Modifying state with a value based on old state?
The Functional update version is documented few pages after this example.
I'm wondering if:
- this example must be changed (although is probably the best type of example for state), or
- a warning box should be added to warn the user this is not the correct way to do.
To be more clear: I know there's nothing wrong with this specific example, but newcomers can quickly try to do something like calling setCount(count + 1) multiple times.
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 Updating state em hooks-state.html e compare seu exemplo de contador com a seção Functional updates em hooks-reference.html. Determine se o exemplo ou um aviso explicativo aborda melhor as atualizações repetidas com base no estado anterior; considera-se concluído quando a documentação orienta claramente quem está começando sem contradizer o exemplo existente.
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
- Razoavelmente clara
- Facilidade para iniciantes
- 45/100