Answer the question
In order to leave comments, you need to log in
How to add and remove a class when I click on an element?
How to add and remove a class when I click on an element?
<a href="/" onClick={this.showAllBook.bind(this)}>All Book</a>
showAllBook(event) {
event.preventDefault();
const name = "One";
this.props.showAllBooks();
showAllBooks() {
const { allBooks } = this.state;
this.setState({filteredBooks: allBooks});
}
Answer the question
In order to leave comments, you need to log in
<a
className={filter === 'all' ? 'active' : null}
onClick={() => setFilter('all')}
>
All Book
</a>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question