Possible conceptual pitfall when discussing accessing a state variable set in a previous render
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 11.8k
- Forks
- 7.9k
- Merge medio
- 1 d 11 h
- PR fusionados (30 d)
- 11
Descripción
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. 🚀
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Lee la sección enlazada “Adjusting some state when a prop changes” de la documentación de React e inspecciona su explicación de useState y setState entre distintos renders. Se considera terminado cuando la sección distingue claramente entre la inicialización del estado y las actualizaciones posteriores, y aborda el malentendido señalado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, react
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 55/100