0
applied_filters: { title: [''], owner: [''], customer: [''] }

One of the states that I have looked like above. I tried to use setState to add value to one of the keys by doing

this.setState({
  applied_filters: [
      ...this.state.applied_filters,
      {title: [...this.state.applied_filters.title, optionItem.option]}
  ]
})

This gives me an error this.state.applied_filters is not iterable

What am I doing wrongly?

1
  • Can you post the full code? How is this rendered? Commented Sep 9, 2019 at 3:54

1 Answer 1

2

According to your first code, applied_filters is an object: applied_filters: { title: [''], owner: [''], customer: [''] }.

However, in the setState call it's being converted to an array (not an object). Try keeping it as an object?

this.setState({
  applied_filters: {
    ...this.state.applied_filters,
    title: [...this.state.applied_filters.title, optionItem.option]
  }
});
Sign up to request clarification or add additional context in comments.

1 Comment

@Dawn17 would you mark it as an answer if it has solved your issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.