Hey Logan, great question.
A good starting place is to improve your component by mapping (looping) <DesktopNavBarPlanets />
instead manually of creating one for each planet. This way, you are not repeating code.
For example:
{planets.map((planet) => {
return (
<DesktopNavBarPlanets
...
planet={planet.name}
/>
);
})}
For state management, you can use one state that takes in the name of the planet, so a string instead of a boolean.
For example:
const [selectedPlanet, setSelectedPlanet] = useState(planets[0].name)
In the <DesktopNavBarPlanets />
component you can then check if the selectedPlanet
matches with props.planet
. If it matches style the border, otherwise leave it transparent.
For example:
style={
props.selectedPlanet === props.planet
? { borderTopColor: `var(--${props.planet}-theme)` }
: { borderBottomColor: 'transparent' }
}
As for changing state onClick
, you’ll have to update the selectedPlanet
state. I’ll leave that to you to figure out :-)