I have two selections that are supposed to filter data, they work but separately, how do I make them filter data together?
When I click on the second select, it resets the data from the first one. They filter the same data array, so the result is new all the time, I don’t understand how to filter an already filtered array
How do I make a joint filter?
//filter data
const [allData, setAllData] = useState<ICompanie[]>(companiesData);
// status filter
const handleStatusFilter = (status: string): void => {
const filterData = companiesData.filter((item) => {
if (item.status === status) {
return item;
}
});
setAllData(filterData);
};
// category filter
const handleCategoriesFilter = (category: string): void => {
const filterData = companiesData.filter((item) => {
if (item.category === category) {
return item;
}
});
setAllData(filterData);
};