-
-
Notifications
You must be signed in to change notification settings - Fork 37
WM5 | AISHA_ATHMAN_LALI | MODULE_REACT | HIGH_SCORES_TABLE | LEVEL 1 & 2 #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
WM5 | AISHA_ATHMAN_LALI | MODULE_REACT | HIGH_SCORES_TABLE | LEVEL 1 & 2 #41
Conversation
.logo { | ||
height: 6em; | ||
padding: 1.5em; | ||
will-change: filter; | ||
transition: filter 300ms; | ||
} | ||
.logo:hover { | ||
filter: drop-shadow(0 0 2em #646cffaa); | ||
} | ||
.logo.react:hover { | ||
filter: drop-shadow(0 0 2em #61dafbaa); | ||
} | ||
|
||
@keyframes logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
a:nth-of-type(2) .logo { | ||
animation: logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.card { | ||
padding: 2em; | ||
} | ||
|
||
.read-the-docs { | ||
color: #888; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may have been left in by accident, because I can't see where it is being used.
}, | ||
]; | ||
|
||
export default allCountryScores; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider removing the default attribute from your export as it is considered a bad practice by most developers. There are multiple reasons for this by a common one is the variable/function name could differ between files and cause confusion if changes are made.
Instead of an import such as
import allCountryScores from "../scores.js"
It would look like
import { allCountryScores } from "../scores.js"
Any variables/functions etc that are referenced inside braces {}
, need to match the declaration in the file you are importing from, improving the consistency of your naming.
If you tried to do
import { nothing } from "../scores.js"
It would fail as there are no variables/functions named nothing
in scores.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, your export can be moved onto the same line as your declaration of your variable, so line 65 is not necessary, the same can be achieved by moving 'export' or 'export default' to line 1.
This would look like
export let allCountryScores = []
Or since const would be more appropriate here export const allCountryScores = []
function App() { | ||
allCountryScores.sort(byName); | ||
return ( | ||
<> | ||
<h1>HIGH SCORES PER COUNTRY</h1> | ||
{allCountryScores.map((country, index) => ( | ||
<table | ||
style={{ | ||
border: "1px solid black", | ||
borderSpacing: "10px", | ||
width: "100%", | ||
}} | ||
> | ||
<thead> | ||
<tr> | ||
<th scope="col" style={{ border: "2px solid red" }} key={index}> | ||
{country.name} | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<ul style={{ borderBottom: "2px solid blue" }} scope="col"> | ||
<td style={{ padding: "1px" }}>player</td> | ||
<td style={{ paddingLeft: "40px" }}>score</td> | ||
</ul> | ||
</tr> | ||
</tbody> | ||
<tbody> | ||
<tr> | ||
{country.scores.map((score, index) => ( | ||
<ul | ||
style={{ borderBottom: "1px solid red" }} | ||
scope="col" | ||
key={index} | ||
> | ||
<td style={{ marginRight: "1px" }}>{score.n}</td> | ||
<td style={{ marginLeft: "90px" }}>{score.s}</td> | ||
</ul> | ||
))} | ||
</tr> | ||
</tbody> | ||
</table> | ||
))} | ||
</> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great Job!
If you wanted another challenge I would encourage you to look into importing individual components, this will be crucial when you start working with larger files.
Here is an article from the React team on this area https://react.dev/learn/importing-and-exporting-components
This can help in a few areas:
- Allow you to create reusable components without duplicating code.
- Cleanup larger files and make your code easier to read.
To use your work as an example, your App function could be refactored to look like:
function App() {
allCountryScores.sort(byName);
return (
<>
<h1> HIGH SCORES PER COUNTRY </h1>
{allCountryScores.map( ( country, index ) => (
<ScoreTable country={country} index={index} />
) )}
</>
);
}
import "./App.scss"; | ||
import "../scores.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import
Self checklist
This is a PR for the High-Scores Table challenge. I have completed level one where I have displayed the given data in tables as requested in the instructions
Questions
I am still struggling with the table. Is there a better way to go about it?