React filter data or show all result

Viewed 86

I have a list of books. it can filter by category. How can I show all books if select "all" category.

books.filter(book => book.category.includes(currentcategory)).map(book =>
<div>
.
.
</div>

Book Categories List

1 Answers

There's plenty of ways to do this, but here's one:

(currentcategory === "all" 
   ? books
   : books.filter(book => book.category.includes(currentcategory))
).map(book => 
 <div>
.
.
</div>
)
Related