[Updating Arrays in State] examples in the beta documentation are using impure function to explain concepts which doesn't seems right
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, learning react and going through the new react doc (beta).
I finished reading about pure functions, but then in a later section (update arrays in state), it showcase multiple examples that seem contradictory to the concept of pure functions in React...
OR I simply did not really understand that concept and If that is the case, I am sorry in advance.
let nextId = 0;
export default function List() {
const [name, setName] = useState('');
const [artists, setArtists] = useState([]);
return (
<>
<h1>Inspiring sculptors:</h1>
<input
value={name}
onChange={e => setName(e.target.value)}
/>
<button onClick={() => {
setName('');
artists.push({
id: nextId++,
name: name,
});
}}>Add</button>
//rest of the code...
isnt using a variable from outside (in this case: let nextId = 0) and just modifying it against the concept of pure function in react?
If this is indeed an impure function, I just think it would be better to promote using pure functions in the visual examples just to not confuse new learners or at least mention that it was made on purpose.
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
Comienza con la sección «Adding to an array» de la documentación enlazada «Update Arrays in State» y compara sus ejemplos con las indicaciones sobre Pure Functions. Determina si los ejemplos de nextId y artists.push necesitan una aclaración o un reemplazo, y considera terminado el trabajo cuando la documentación ya no confunda estos conceptos.
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
- Bastante claro
- Aptitud para principiantes
- 35/100