Answer the question
In order to leave comments, you need to log in
How to add a new value to state in React?
I want to use state to transfer data between two components and I want the parent component to add new values \u200b\u200bin the state at the right time, thereby the child component updates the table when the data in the state changes. How is this possible to do??
Thanks
Answer the question
In order to leave comments, you need to log in
If you need to dynamically add a new value, then
state = {array : []}
)const newArray = this.state.array
newArray.push('test')
this.setState({array : newArray})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question