0

here's my state:

state={show: false,addDisplay:true,key:'',sections: [{title:'primary',
                                                         data:['a','b']
                                                      }]
        }

and here I'm trying to setState:

this.setState({...this.state,sections: [{title:'primary',
                                      data: [...this.state.sections.data,this.state.input]
                                       }]
             })

why is this.state.sections.data undefined?

1
  • 2
    Because this.state.sections is an array, you aren't accessing it like it's an array Commented Jun 5, 2018 at 14:50

1 Answer 1

1

this.state.sections is an array, try with ...this.state.sections[0].data

Sign up to request clarification or add additional context in comments.

Comments

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.