减速器表现得很奇怪



直奔问题。每次我与新用户创建一个新房间时,该应用程序都可以正常工作。但是,一旦我尝试将新用户添加到现有房间,我就会丢失该房间中的所有先前用户。

代码可在 - https://codesandbox.io/embed/xenodochial-tree-w75r8

假设我要将两个用户(max 和 payne(添加到一个名为 cool 的全新房间,我希望输出如图所示。

从房间 :


chatData:
  cool:
  message: {}
  users: Array(2)
      0: "max"
      1: "payne"
      length: 2
      proto: Array(0)
      proto: Object
  cricket: {users: Array(3), messages: Array(2)}

I think you need to copy the previous state that you had inside the users array before appending the new value. That's why you lose all your previous users.

case "EXISTING_ROOM_NEW_USER":
  return {
    ...initState,
    [action.payload.roomname]: {
      users: [...initState[action.payload.roomname].users, action.payload.username],
      message: {}
    }
  };

相关内容

  • 没有找到相关文章

最新更新