我的应用包含多个对话,每个对话都没有我自己的消息。
聊天屏幕
const mapStateToProps = (state: any) => {
return {chatMessages: state.chatMessages.messageByConversationId[state.chatMessages.conversationId]};
}
减少邮件加载量:
export const subscribeChatMessagesSuccess: Reducer<ImmutableChatMessagesState> = (
state: ImmutableChatMessagesState,
{ payload }: AnyAction & { payload?: SubscribeChatMessagesSuccessParams }) =>
payload
? {
...state,
requesting: false,
messageByConversationId: {
...state.messageByConversationId,
[payload.conversationId]: payload.chatMessages
,
},
}
: state;
这很好用!放置消息时,屏幕触发器将重新呈现。
当我尝试添加ChatMessage时,问题开始了:
export const addChatMessage: Reducer<ImmutableChatMessagesState> = (
state: ImmutableChatMessagesState,
{ payload }: AnyAction & { payload?: AddChatMessageParams }) => {
return payload
? {
...state,
messageByConversationId: {
...state.messageByConversationId,
[payload.conversationId]: [...state.messageByConversationId[payload.conversationId], payload.chatMessage],
},
}
: state;
这次,我可以看到更新成功,并且ChatMessages计数器(在redux上)增加了+1。 但是渲染不会触发Screen的渲染。
正确的方法是什么?