I need some help with a class componenent in React .
I'm tring to change the class of the li after mapping the array 'list' . Could you please tell me how can I use the state in this case . When I click on the
I can do this without mapping the list vut i dont' want to repeat the code for each Composant .
Thank you very much for your help and I hope i will be understood
const list = ['Biographie', 'CV', 'Blog'];
class Navbar extends Component {
state = {
Biographie: true,
CV: false,
Blog: false,
};
show = (e) => {
list.map(item=> this.setState ({ [item]: false}))
this.setState({ [e.target.id]: true });
};
render() {
return (
<div className="navbar">
<ul className="list">
{list.map((item) => (
<li
onClick={this.show}
id={item}
className={this.state ? 'active' : ''} // How can I change class when state = true ?
>
{' '}
{item}
</li>
))}
</ul>
<Biographie info={this.state.Biographie} />
<CV info={this.state.CV} />
<Blog info={this.state.Blog} />
</div>
);
}
}