[Suggestion]: Fix the `data.js` file part of the solution for Challenge 4 in "Choosing the State Structure" chapter
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 70/100
- Tipo di issue
- Documentazione
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, react
- Ambito
- documentation
Direzione di ricerca
Apri la soluzione di Challenge 4 collegata dalla pagina Choosing the State Structure ed esamina il suo file data.js. Conferma che isStarred non venga utilizzato dalla soluzione fornita, quindi verifica che la challenge visualizzata e il riepilogo rimangano coerenti dopo la rimozione della proprietà inutilizzata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
The data.js provided in the solution for "Challenge 4" has a property called isStarred which is unused in the provided solution for the challenge:
export const letters = [{
id: 0,
subject: 'Ready for adventure?',
- isStarred: true,
}, {
Thus my suggestion is to remove the isStarred property from data.js file in challenge 4
Page
https://react.dev/learn/choosing-the-state-structure#recap
Details
The presence of the unused isStarred property can potentially confuse a beginner following the documentation, because they might have gone through the section on Avoiding Redundant States. I mean to say that they might end up writing a solution which utilises the isStarred property like shown below, which also solves the challenge:
import { useState } from 'react';
+import { letters as initialLetters } from './data.js';
import Letter from './Letter.js';
export default function MailClient() {
+ const [letters, setLetters] = useState(initialLetters);
+ const selectedCount = letters.filter(({isStarred}) => isStarred).length;
function handleToggle(toggledId) {
+ setLetters(letters => letters.map(letter => {
+ if (letter.id === toggledId) {
+ return {
+ ...letter,
+ isStarred: !letter.isStarred
+ }
+ } else return letter;
+ }))
}
return (
<>
<h2>Inbox</h2>
<ul>
{letters.map(letter => (
<Letter
key={letter.id}
letter={letter}
+ isSelected={letter.isStarred}
onToggle={handleToggle}
/>
))}
<hr />
<p>
<b>
You selected {selectedCount} letters
</b>
</p>
</ul>
</>
);
}
Although the above solution works, it has the following cons:
Tight Coupling: OverloadingisStarredfor both "selected" and "starred" behaviours creates coupling between two potentially distinct concepts. If the app later needs to treat "starred" and "selected" as separate attributes, refactoring will be necessary.Side Effects: ModifyingisStarredmight have unintended consequences elsewhere in the app if other features or components depend on it strictly representing "starred" status.
- Lingua principale
- JavaScript
- Stelle
- 11.8k
- Fork
- 7.9k
- Merge medio
- 16h 6m
- PR unite (30g)
- 7
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.
Altre issue di reactjs/react.dev
-
type: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
-
bug: unconfirmed
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
type: typos
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
bug: unconfirmed
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Tutte le issue di reactjs/react.dev
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Seeed-Studio/wiki-documents#5655 · 2 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Edit: CW+ Apertachannels:edit check:passed
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
01 type: bug 30 needs: triage 99 tag: UX Accessibility
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
quarto-dev/quarto-cli#14915 ·