Explain index as key can be ok
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 11.8k
- Fork
- 7.9k
- Merge medio
- 1g 11h
- PR unite (30g)
- 11
Descrizione
The pitfall warning on https://beta.reactjs.org/learn/rendering-lists states that using index or random for keys is bad. However, this is the only mention of using indexes of keys. I think it should state that using indexes is bad, but it should also be clear that using random values much worse.
The problem is using index as key is a well known anti-pattern in the React world. People come up with much worse solutions, e.g. use a random key, to get rid of ESLint warnings.
Also there are legitimate use cases for an index as a key, for example when rendering a static list of data. I think this should be acknowledged in the Where to get your key section.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Apri la pagina Rendering Lists all’indirizzo https://beta.reactjs.org/learn/rendering-lists e leggi l’avviso sulle insidie e la sezione “Where to get your key”. Aggiorna la spiegazione in modo che distingua tra key basate sull’indice e key casuali e riconosca le liste statiche come un caso legittimo per le key basate sull’indice; il lavoro è completato quando le indicazioni sono chiare e coerenti in entrambi i punti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, react
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 58/100