[Suggestion]: clarify behaviour of ref callbacks
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
Summary
The described behaviour for ref callbacks with null as an argument is ambiguous.
Page
https://react.dev/reference/react-dom/components/common#ref-callback
Details
From https://react.dev/reference/react-dom/components/common#ref-callback:
React will also call your ref callback whenever you pass a different ref callback. In the above example, (node) => { ... } is a different function on every render. When your component re-renders, the previous function will be called with null as the argument, and the next function will be called with the DOM node.
If I understand correctly, the emphasised sentenced is not correct when the ref callback returns a clean up function, as is the case in the referenced example. This needs to be clarified.
There is a note later on which helps a bit, but I still think this sentence could be made clearer so it makes sense in isolation.
Reduced test case to confirm this behaviour: https://stackblitz.com/edit/vitejs-vite-2r9rn6m2?file=src%2FApp.tsx&terminal=dev
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
Empieza por la sección ref-callback de la página react.dev enlazada y revisa el caso de prueba reducido de StackBlitz para verificar el comportamiento descrito. Aclara la frase resaltada para que siga siendo correcta cuando el callback devuelva una función de limpieza y asegúrate de que la redacción tenga sentido sin depender de la nota posterior.
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
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 72/100