Component don't update after changing messages.sent/received = true;
this.state.messages[this.state.messages.indexOf(message_id) + 1].sent = true;
this.setState({ messages: this.state.messages });
Component should re render with a tick mark
This will not work. State Object is always changing with thesetState() Method and not by the assign operator.
Well i did tried this too
let temp_data = this.state.messages
temp_data[temp_data.indexOf(message_id) + 1].sent = true;
this.setState({ messages: temp_data })
This isn't working too..
You should use immutable functions in order to keep it working.
this.setState({ messages: this.state.messages.map(m => {
if (m.id === message.id) {
return {
...m,
sent: true
}
}
return m;
})
Help wanted #808 @brunocascio
I just found an easy fix. Fork this repo, and in GiftedChat.js, instead of using this._messages and this.getMessages() to update messages to MessageContainer, you set a state (like this.state_messages) and call setState in componentDidMount(and comment out this.setMessages())
the bug of tick not rerendering on receive is due to this._messages and this.getMessages() do not rerender the GiftedChat component, but setState does the job.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
You should use immutable functions in order to keep it working.