reactjs / reactjs/react.dev

[Suggestion]: Documentation states mutation is "not recommended" when it fundamentally doesn't work, misleading beginners about how React state functions

Ouverte
#8,147 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

type: documentation
Langage dominant
JavaScript
Étoiles
11.8k
Forks
7.9k
Merge moyen
1 j 11 h
PR mergées (30 j)
11

Description

Summary

The React documentation states that mutating state is "not recommended" and that developers can "get away with it," when in fact mutating state doesn't trigger re-renders at all. This misleads beginners into thinking mutation is a working anti-pattern rather than fundamentally broken code that prevents React from updating components.

Page

https://react.dev/learn/updating-objects-in-state

Details

Multiple sections in the React documentation misleadingly describe state mutation as "not recommended" or something you can "get away with," when the fundamental issue is that mutating state doesn't trigger re renders. This appears in at least:

The tic tac toe tutorial's "Why immutability is important" section
The last "Deep Dive" in the "Updating Objects in State" page in the Adding Interactivity section

Both sections list various reasons why mutation is discouraged (debugging, optimizations, features, etc.) but bury or omit the primary issue: if you mutate state, React won't re render your component because it can't detect the change.
The "Updating Objects in State" page is particularly problematic as it says:

"In practice, you can often 'get away' with mutating state in React"

My experience as a beginner:
This kind of language is incredibly confusing when learning React. React detects state changes by checking if the reference to the state has changed. When you mutate an object or array, you're modifying the same reference, so React doesn't know anything changed and doesn't re-render. Yet the official documentation makes it sound like mutation is just a bad practice that technically functions. When I read "not recommended" and "you can get away with it," I thought it was like using var instead of const, discouraged but functional most of the time.
The documentation's phrasing suggests there are scenarios where mutation works, but React fundamentally requires a new reference to detect changes. Mutation will not trigger a re-render.

Why this matters:
• React.dev is the official resource for learning React
• These are fundamental concepts that beginners encounter early
• This framing suggests mutation is a working anti-pattern rather than broken code
• Beginners won't understand that immutable updates are required for React to function, not just a best practice

Suggested improvement:
All sections discussing state mutation should lead with something like this:

"Mutating state directly doesn't trigger re-renders. When you mutate an object or array in place, React cannot detect the change because the reference remains the same. Your component will not re-render update."

Then follow with the additional benefits of immutability. Remove phrases like "get away with" that suggest mutation sometimes works. It only appears to work when other factors trigger re-renders, which should be made more clear.

Scope:
This language should be audited across all documentation pages that discuss state updates to ensure consistent, accurate messaging about why immutability is required, not just recommended.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par la section « Why immutability is important » du tutoriel tic-tac-toe et par le « Deep Dive » final de « Updating Objects in State. » Examinez le reste de la documentation sur la mise à jour de l’état pour y repérer des formulations similaires, puis révisez les explications afin que la conséquence sur le re-render soit claire avant les avantages secondaires ; le travail sera considéré comme terminé lorsque les pages concernées expliqueront toutes de manière cohérente pourquoi la mutation directe échoue.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
react
Domaine
documentation
Type d'issue
Documentation
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.