I have a state variable in react as:
this.state = {
formStatus : {
approved : true,
rejected : true,
pending : true
}
}
and a dynamic array whose value can contain either one or all of these values
appliedFilters = ['approved', 'rejected', 'pending']
Now What I want to do is set my state keys to false if the array doesn't contain them.
For example, if the array is ['approved', 'rejected'] then my state should be set as:
this.state = {
formStatus : {
approved : true,
rejected : true,
pending : false
}
}
I want to do it using ES6 map() if possible.
I have done something like this but it is not working:
appliedFilters.map(filter => {
this.setState(prevState => ({
formStatus: prevState.formStatus.map(
status => (status === filter) ? true : false
)
}))
})