[Suggestion]: Fix the `data.js` file part of the solution for Challenge 4 in "Choosing the State Structure" chapter
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 1/5
- Tempo estimado
- Menos de uma hora
- Facilidade para iniciantes
- 70/100
- Tipo de issue
- Documentação
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- javascript, react
- Domínio
- documentation
Direção de pesquisa
Abra a solução do Challenge 4 vinculada na página Choosing the State Structure e inspecione o arquivo data.js. Confirme que isStarred não é usado pela solução fornecida e, em seguida, verifique se o challenge exibido e o resumo continuam consistentes depois que a propriedade não utilizada for removida.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- JavaScript
- Estrelas
- 11.8k
- Forks
- 7.9k
- Merge médio
- 16h 6min
- PRs com merge (30d)
- 7
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de reactjs/react.dev
-
type: documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 82/100
-
bug: unconfirmed
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
-
type: typos
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
-
bug: unconfirmed
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Todas as issues de reactjs/react.dev
Issues semelhantes
-
documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
githubnext/gh-aw-workshop#3692 ·
-
agent/guide documentation hive/hosted-available-lke648397-260827-5n31
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 90/100
-
Add: BuyPass TV Abertachannels:add check:passed
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
S: triage
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 85/100
-
bug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
apache/cloudstack#14222 ·