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);
Source: stackoverflow.com
Related Query
- Looping thru nested array, and also being able to search/filter it
- React- Filter array based on search and dropdown values
- I need to search data in an array according to filter and set start form index of 1
- Search filter in reactjs, say i have an array of data with multiple columns and rows
- loop throught array of objects then filter and also create new object within
- React looping and creating new array with nested objects
- Search nested array of objects and return whole path of all matching items
- how to filter through an array and check if a nested object includes a value of true using reselect in redux
- How to filter array of nested objects with unknown depth based on given search term
- How to use filter from an array while fetching graphql query and also must keep the array order?
- Filter an Array through id and then mapping through a nested array inside
- How to filter and highlight text in the Dynamic nested array of JSON objects based on text match incase sensitive
- How to filter Dynamic nested array of JSON objects based on text match with both upper and lower case
- How to compare nested array with the map or filter and only return with first match inside?
- How to search and filter in array of objects on setState
- ReactJS/ React-Router: How to filter nested array and objects based on url path parameters?
- Looping over Object with key being a string and value being an array of 2 numbers
- React - filter nested array and update the state
- How to filter and sort the same array of object state in redux?
- React: issue with the search and filter function
- Javascript Filter or Reduce each JSON object by child array of tags which contains search word
- Pushing and Pulling an nested array with setState with Javascript
- React search and filter methods issue
- Arrays - Javascript - filter array of objects using input search
- How to implement a Search inside a Nested Array of Objects?
- Accessing nested keys in object and compare them to other object keys, but the 2nd one is an array of objects
- How can I filter through an array of objects based on a key in a nested array of objects?
- Search nested array of objects
- How to edit/update an object in an array and keep all other nested data?
- Filter array by finding multiple conditions in nested array of objects
More Query from same tag
- How to use react-compound-timer in my React app
- firebase export issue in react
- How to redraw specific DOM asynchronously in Mithril
- Activity needs to be set if initial lifecycle state is resumed
- Equivalent of a yield take Redux Saga in Redux thunks
- Use fetch results to make another fetch request (JS/React)
- I have this child component where you can submit a form, however, e.preventDefault() does not work
- React UI not re-rendering on click even though DB is updated correctly. After second click, UI re-renders
- React Bootstrap Validation use validated input in sub component
- How can I change the array key value before passing to the state in react?
- Undefined value for initial state in ReactJS
- React hook - HowTo pass state to child components
- How would I place each bike in its assigned category? ReactJS
- Connected component initial render fails because Redux state is not yet populated from server
- Reactjs - proptypes check with oneOfType
- Browserify failing to compile react
- Update React Child Animated Component
- What react lifecycle component to use to update state after an axios post
- How to navigate between pages using Electron and React?
- Dynamically style components passed as props
- Is there a way to unit test an innaccessible callback function that is called from a child React component using jest
- my data test id is there but my test cannot find it react enzyme jest unit tests
- Sending onMouseDown from parent to child
- eslint JSX return error "expression expected"
- React Checkbox component takes two clicks to change to checked
- Imports path in react
- Unhandled Rejection (TypeError): keytar.setPassword is not a function
- Exposing a method on a React Component
- Unable to resolve React-Navigation
- How to log issues to a file with NodeJS/ExpressJS?