Possible conceptual pitfall when discussing accessing a state variable set in a previous render
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
Hi there!
In this section: https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
It took me a while to understood that prevItems would not be changed until setItems was invoked on it. What tripped me there was that I thought that useState(X) always set items to X on every re-render. Once I understood that prevItems is set to X only when the state is initialized, everything is clear.
This might perhaps be a good place in the docs to clarify (either on a couple of sentences or on its own Pitfall section) that setState will only initialize a value, but not update it during a re-render.
I take this opportunity for congratulating the team on the new React docs. There are one of the best technical documentation pieces I've read in my entire career. 🚀
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
Leia a seção vinculada “Adjusting some state when a prop changes” na documentação do React e examine a explicação de useState e setState entre renderizações. Considera-se concluído quando a seção distingue claramente a inicialização do estado das atualizações posteriores e aborda o mal-entendido relatado.
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