I've been trying for hours to figure this out, and I'm sure the answer is simple. When an Item is clicked, it will ultimately create a filter for my todo list. What I'm struggling to do is apply conditional styling, so that the font color of the 'active' item is blue.
I have included status as a prop, but I can't seem to use it as well as props inside the styled components.
From my App.js:
import { useState } from 'react'
function App() {
const [ status, setStatus ] = useState("all")
return (
<Filter status={status} setStatus={setStatus}/>
)
}
Filter.js
const Container = styled.div`
display: flex;
justify-content: center;
`
const Item = styled.p`
color: red;
// I'm trying to do something like this..
${(status, props) => {
if (status === props.id) {
return `
color: blue;
`
}
}}
`
export const Filter = ({ setStatus, status }) => {
const statusHandler = (e) => {
if (e.target.id) {
setStatus(e.target.id)
}
}
return (
<div>
<Container onClick={statusHandler}>
<Item id="all">All</Item>
<Item id="active">Active</Item>
<Item id="completed">Completed</Item>
</Container>
</div>
)
}
