Updating messages properties will not trigger message bubble re-render
See original GitHub issueIssue Description
Updating messages attributes will not trigger message bubble re-render. To be more precise, updating a seen (boolean) property (similar to seen or received), will not trigger the message to be re-rendered. Messages are re-rendered only when a new message is added to the messages array, not when one particular message is updated.
Steps to Reproduce / Code Snippets
- Populate a chat with x messages
- Update a boolean property on any of the messages currently in chat
// https://github.com/FaridSafi/react-native-gifted-chat/blob/master/src/MessageContainer.js#L67
componentWillReceiveProps(nextProps) {
if (this.props.messages === nextProps.messages) {
return;
}
const messagesData = this.prepareMessages(nextProps.messages);
this.setState({
dataSource: this.state.dataSource.cloneWithRows(messagesData.blob, messagesData.keys)
});
}
Expected Results
Messages, or single message, should be updated and re-rendered whenever any of its properties are updated.
Additional Information
- React Native version:0.49.5
- react-native-gifted-chat version: 0.3.0
- Platform(s) (iOS, Android, or both?): both
Possible solution
Removing the empty return within componentWillReceiveProps of MessageContainer.js, which fails to properly compare if messages are truly the same or not.
// https://github.com/FaridSafi/react-native-gifted-chat/blob/master/src/MessageContainer.js#L67
componentWillReceiveProps(nextProps) {
//if (this.props.messages === nextProps.messages) {
//return;
//}
const messagesData = this.prepareMessages(nextProps.messages);
this.setState({
dataSource: this.state.dataSource.cloneWithRows(messagesData.blob, messagesData.keys)
});
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:34 (1 by maintainers)
Top Results From Across the Web
React doesn't rerender component when props change
The problem is that you are mutating state, not creating a new one. When you set state in a function component, react will...
Read more >Textmesh pro is not updating when changing text ...
There are several things that happens with this error: 1.- Text Mesh Pro is not updating text even though i use forceMeshUpdate to...
Read more >React re-renders guide: everything, all at once - Developer way
The guide explains what are re-renders, what is necessary and unnecessary re-render, what can trigger a React component re-render.
Read more >7 Rerendering Partial Page Content - Oracle Help Center
In the Structure window, select the trigger component (that is, the component whose action will cause the PPR):. Expand the Common section of...
Read more >5. Rendering views - Spring
The list is updated in view scope before each render. ... binder element is not specified all public properties of the model are...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve been trying to implement message reactions similar to Facebook messenger, but on Android only the most recent message and the first message update properly when their props update. Like if I tap on a message to bring up the reaction bar, the reaction bar (which I implement as an absolute positioned view on top of my custom message bubble) will only render if its the top or most recent message.