<form
onSubmit={(e) => {
e.preventDefault();
const newSubCatInput = newSubCategory.current;
if (!newSubCatInput || newSubCatInput.value.trim().length < 1) return;
setCategories((prev) => {
const oldCategories = Array.from(prev);
const categoryToEdit = oldCategories[activeCategory];
if (!categoryToEdit) return oldCategories;
oldCategories.splice(activeCategory, 1, {
...categoryToEdit,
subFilters: [...categoryToEdit.subFilters, newSubCatInput.value],
});
return oldCategories;
}
);
newSubCatInput.value = "";
newSubCatInput.blur();
}}
>
<form
onSubmit={(e) => {
e.preventDefault();
const newSubCatInput = newSubCategory.current;
if (!newSubCatInput || newSubCatInput.value.trim().length < 1) return;
setCategories((prev) => {
const oldCategories = Array.from(prev);
const categoryToEdit = oldCategories[activeCategory];
if (!categoryToEdit) return oldCategories;
oldCategories.splice(activeCategory, 1, {
...categoryToEdit,
subFilters: [...categoryToEdit.subFilters, newSubCatInput.value],
});
return oldCategories;
}
);
newSubCatInput.value = "";
newSubCatInput.blur();
}}
>