How can I update react redux toolkit store using dispatch?

Viewed 31

I am tried to edit an object data of an array containing more than one object in react redux toolkit store with dispatch but it does not work. Also, I want to navigate to other component after dispatch similarly does not work . Although I was selected the item which I want to change by id using filter() method and update the state with action. payload it printed in the console exactly as I want but state still keeps old data.


import editUserAccountR from .............

        const updatedData = {
                      id,
                      name,
                      age,
                      lang,
                    };
        //old state contain the same properties
                    dispatch(editUserAccountR(updatedData));
                    navigate("/otherComponent");
               //  -----------------------------------------------------
        store :
       // --------------------------------------
         editUserAccountR: (state, action) => {
              state.authorization.userAccounts =
                state.authorization.userAccounts.filter((item) => {
                  if (item.id === action.payload.id) {
                    item = action.payload;
                  }
                  return item;
        //item updated successfully but state not
                });`enter code here`
            },
0 Answers
Related