How to change expanded state of every object in array list. I want to change states inside eachClose() function. Every time when I trying change state of objects in array list i got that error from React compiler:
TypeError: item.setState is not a function
class Item extends React.Component{
constructor(props){
super(props);
this.state = {
expanded: false,
};
}
class ItemList extends React.Component{
constructor(props){
super(props);
this.state = {
list: [
<Item />,
<Item />,
<Item />,
<Item />,
<Item />,
]
};
}
eachClose = () => {
this.state.list.map ((item, i) => item.setState({expanded: false}))
}
render(){
return(
<div className="users">
{this.state.list.map ((item, i) => <Item id={i} key={i} />)}
<button onClick={this.eachClose}>Click</button>
</div>
);
}
}