-3

I have a react app with a state element like this:

state = {

  options: {

    xaxis: {
      categories: []
    }
  }

}

However, in this function, when I try to set the state of categories I get an error that it isn't expecting a format with periods like options.xaxis.categories

this.setState({
  options.xaxis.categories: this.state.resultDates
});

How can I properly set the state of that array element?

1

1 Answer 1

1

That's not the correct syntax. This is correct syntax.

this.setState({
  options: {
    ...this.state.options,
    xaxis: {
      ...this.state.options.xaxis,
      categories: this.state.resultDates
    }
   }
});
Sign up to request clarification or add additional context in comments.

1 Comment

wow, I was way off! I don't know why I couldn't find that documented anywhere. I really appreciate it, that worked great!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.