需要替换react redux中的列表



我试图设置代码块不起作用的用户详细信息的属性。

import CHATS from '../actions/ChatMessages';
import MESSAGES from '../actions/Messages';
import SEARCH from '../actions/SearchUser';
const chatReducer = (state = {}, { type, payload }) => {
switch (type) {
case CHATS:
return { ...state, ...payload };
case SEARCH:
return {
...state,
userDetails: [...payload.userDetails]
};
case MESSAGES:
let index = state.chats.findIndex(
chat => chat.chatId === payload.chatId
);
if (index !== -1) {
let conn = state.chats[index];
const msg = payload.msg;
conn.lastMsg = msg;
const messages = [...conn.messages, payload];
const newState = { ...state };
newState.chats[index] = { ...conn, messages };
console.log("state ", newState);
return newState;
}
return state;
default:
return state
};
};
export default chatReducer;

userdetails字段不会替换该值。状态对象有什么问题吗?

以下内容有效。在重新启动我的IDE之后。

import CHATS from '../actions/ChatMessages';
import MESSAGES from '../actions/Messages';
import SEARCH from '../actions/SearchUser';
const chatReducer = (state = {}, { type, payload }) => {
switch (type) {
case CHATS:
payload.msgType = "";
return { ...state, ...payload };
case SEARCH:
return { ...state, userDetails: [...payload.userDetails] };
case MESSAGES:
let index = state.chats.findIndex(
chat => chat.chatId === payload.chatId
);
if (index !== -1) {
let conn = state.chats[index];
const msg = payload.msg;
conn.lastMsg = msg;
const messages = [...conn.messages, payload];
const newState = { ...state };
newState.chats[index] = { ...conn, messages };
return newState;
}
return state;
default:
return state
};
};
export default chatReducer;

相关内容

  • 没有找到相关文章

最新更新