it seems like a stupid question but its been bugging me for a while now.
assume that my render function displays a list like so:
render(){
return (
<div>
<button onClick={()=>{this.setState({dummyList2:[...this.state.dummyList2,<h2>world</h2>]})}}> add to dummy list 2 </button>
{this.state.dummyList1.map(el=>el)}
</div>
)
and my state in the constructor is as follows:
state={
dummyList2:[]
dummyList1:[<h1>{this.state.dummyList2.map(el=>el)}</h1>]
}
the behavior I expect is clicking the button would add item to dummyList2 and since I am rendering dummyList1 which contains the second list, it should display the updated elements however this is not working and I'm not sure why
Thanks in advance!
EDIT
For a better view of what I am trying to achieve, I have created a sandbox
prevStatewhile assigning the new element to the array. If you don't do so it may lead to inconsistency. Also, where do you havedummyList2insidedummyList1?react-grid-layoutcomponent and what i am trying to do is have nested ones basically the idea is i have a toolbox through which a user can drag items to the parent grid and can also drag items to the child grid as well .. i succeeded in updating the state i can see it changing and thecomponentDidUpdateis getting fired however the .map for the the line where i call{this.state.dummyList2.map(el=>el)}is only getting called once. state update isnt getting picked updummyList2, so why is supposed to be re-rendereddummyList1with any new elements?