I'm trying to create a button to change the css of a component (Card.js) on Click but I'm not able to do it since I have to use a map function for a Tab.
That's the code.
The component Card.js:
const Cardbox = styled.div`
...
`
const Cards = styled.div`
width: 150px;
height: 220px;
background: url(${props => props.bg}) no-repeat top center;
`
const Name = styled.h3`
...
`
const Role = styled.p`
...
`
const Card = props => (
<Link to={props.link}>
<Cardbox>
<Cards bg={require(`./../images/Cards/${props.title}_Card.jpg`)}/>
<div>
<Name>{props.title}</Name>
<Role>{props.text}</Role>
</div>
</Cardbox>
</Link>
)
export default Card
Tab.js component (I get data from a constant file):
class Tabs extends React.Component {
constructor(props) {
super(props);
this.state = {
...
}
}
...
makeHeroCard = (hero, index) => (
<Card
title={hero.name}
text={hero.type.join(', ')}
image={
require(`./../images/Cards/${hero.name}_Card.jpg`)
}
link={hero.name}
key={index}
/>
)
render() {
...
return (
<div>
<button>Click here and change css</button>
<AppBar>
<Tabs>
<Tab label="Item One"/>
<Tab label="Item Two"/>
<Tab label="Item Three"/>
</Tabs>
</AppBar>
{value === 0 && (
<TabContainer>
<div className="GroupScroll">
<div className="Group">
{heroCards.map((hero, index) => this.makeHeroCard(hero, index))}
</div>
</div>
</TabContainer>
)}
{value === 1 && (
<TabContainer>
<div className="GroupScroll">
<div className="Group">
{heroCards
.filter(hero => hero.type.includes('TANK'))
.map((hero, index) => this.makeHeroCard(hero, index))
}
</div>
</div>
</TabContainer>
)}
</div>
)
}
}
export default Tabs
What I'd like to do on clicking the button is: 1. change width,height and src of the img; 2. hide h1 and p.
How can I do it using {heroCards.map(...)}
?
Thanks in advance.