To try to make an attribute of one of the objects in an array of objects switch between true and false follow code:
Initial status:
constructor(props) {
super(props)
this.state = {
post: [{
nome: '',
conteudo: '',
comment: false
}]
}
this.handleClickComment = this.handleClickComment.bind(this)
}
Method that changes the comment attribute for each object in the array (corrected):
handleClickComment(postagem) {
postagem.comment = !postagem.comment
let i = postagem.id -1
this.setState({...this.state.post[this.state.post[i] = postagem]})
}
This method is calling in an onClick event, and takes as parameter the object in question as mapped in another component, but whenever the event the comment attribute simply does not change. Could anyone tell me what's wrong?
Edit
I was able to solve the problem of updating the code that worked perfectly, updated the value of the attribute without changing the state of the application directly, always instantiate a new array with the new parameters. Thank you all for the help.