score:2

Accepted answer

keep you filter string on state

const [chargetitlesearch, setchargetitlesearch] = usestate("");

then you can create the filter function

const filterfn = t => !chargetitlesearch || t.match(chargetitlesearch); // or whatever

then use the filter

cat.charges.filter(c => filterfn(c.title)).map(...);

if you want to omit any categories that have no data after filtering:

// make a new list with the charges in each category filtered out
const filterchargedata = chargesdata.map(c => {
  return { ...c, charges: c.charges.filter(cc => filterfn(cc.title))};
});

// filter the categories based on whether or not they contain any charges.
const nonemptycategories = filterchargedata.filter(c => c.charges.length);

Related Query

More Query from same tag