reactjs / reactjs/react.dev

[Tutorial] Potentially confusing explanation of how a component rendering is triggered

Aperta
#3,894 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
JavaScript
Stelle
11.8k
Fork
7.9k
Merge medio
1g 11h
PR unite (30g)
11

Descrizione

I'm new to React and when learning, I first went through the tutorial and then went through the docs. In the tutorial I didn't quite understand why we absolutely have to use the setState() method. But when going through the Using State Correctly and then the API docs for setState() I understood why. Then I went back to the tutorial to see why I couldn't get this from the tutorial. State is introduced in the Making an Interactive Component section.

I think it'd be better if it's explicitly mentioned here that state changes are what causes components to be re-rendered and hence, one shouldn't attempt to modify state directly. The following part particularly is what gave the wrong impression I think. I took this to mean that it's events such as onClick that triggers a rendering.

By calling this.setState from an onClick handler in the Square’s render method, we tell React to re-render that Square whenever its <button> is clicked.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Rivedi la sezione „Making an Interactive Component“ del tutorial insieme alla documentazione collegata „Using State Correctly“ e „setState() API“. Concentrati sulla spiegazione citata e verifica che il testo rivisto distingua chiaramente gli eventi di clic dai cambiamenti di stato. Il lavoro è completato quando un nuovo arrivato comprende perché setState() attiva il rendering e perché lo stato non deve essere modificato direttamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, react
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
1/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.