Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
Remove nested object in React State

In React I have some filters in a state:

this.state {
   filters: [countries: {parameterName: 'country', value: 'England'}, 
                        {parameterName: 'country', value: 'Greenland'}]
}

In an onClick-Handler function I receive one of these objects:

removeFilter(filter) {     
        console.log('remove->', filter);
        // outputs: {value: 'England', parameterName: 'country'} 
}

Is there a way to remove that object from my state using setState? I currently try using 'find' to get the object inside the state itself but I'm not sure how to remove it:

let found ? this.state.filters[filter.parameterName].find(element => element.value === filter.value))
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Looks like this is a react state management question, so you want to avoid mutation, by that I mean that you don't want to manipulate the original array object. So you want to create a new array excluding the one that you want to remove. Like:

const newFilter = countryFilter.filter(f => f.value !== filter.value);

then you want to keep constructing the new state object, and place this array where it belongs on the state object.

I think the state object you pasted in your question is not correct, so I am not trying to guess the correct structure of it.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!