react.js – Update the status with React and Websockets

I am working on a reaction app with Websocket. In this app there is a socket event listener that returns three types: add. change, and remove, Certain status updates are performed based on the type of reception.

My question would be based on the code below, I have to mutate it correctly users State because I'm not sure if it will follow the principle of the reaction in terms of updating states.

ws.on("connect", () => {


ws.on("feed", response => {
  const prev = response.old_val;
  const next = response.new_val;
  const type = response.type;
  setUsers(users => {
    let currentUser = (...users);
    let index;
    switch (type) {
      case "add":
        return (...users, next);
      case "change":
        index = users.findIndex(u => ===;
        currentUser(index).name =;
        return currentUser;
      case "remove":
        index = users.findIndex(u => ===;
        currentUser.splice(index, 1);
        return currentUser;
        return currentUser;