需要替换 react redux 中的列表
Need to replace the list in react redux
我正在尝试设置代码块不起作用的 userdetails 的属性。
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;
我正在尝试设置代码块不起作用的 userdetails 的属性。
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;