I am using React.js and Styled Components. I would like to change the text color only that I clicked among the same components tags.
This is what I did, but I think there is the easiest way to do it. please give me some advice.
import styled from "styled-components";
function Nav() {
let [picked, setPicked] = useState(new Array(3).fill("black"));
const handleA= () => {
setPicked(["orange", "black", "black"]);
};
const handleB = () => {
setPicked(["black", "black", "orange"]);
};
const handleC = () => {
setPicked(["black", "black", "black"]);
};
return (
<Container>
<List onClick={handleA} style={{ color: picked[0] }}> A </List>
<List onClick={handleB} style={{ color: picked[1] }}> B </List>
<List onClick={handleC} style={{ color: picked[2] }}> C </List>
</Container>
);
}
const List = styled.li`
list-style-type: none;
display: inline;
padding: 0px 10px 0px 10px;
border-left: 1px solid black;
cursor: pointer;
outline: 0 none;