Currently, my project utilizes the '@ngrx/store' to store data locally for display in a table. A key component of this functionality is the ability to edit and update user information.
All necessary setup such as user actions, effects, reducer, and selector have been completed. Data is accessed from a remote database via an API connection.
One challenge I am facing is that when I have a list of users stored in memory, I encounter difficulties editing them. It appears that in order to update a user, I must clone the object, make changes, and then pass it to the update function.
Despite these efforts, I have been unable to successfully update the local in-memory copy of the users array state without needing to retrieve all data from the remote server again.
Here is a snippet of my reducer code:
case Actions.UPDATE_SUCCESS: {
let user= action.payload as User;
let position = state.data.findIndex(x => x.id === user.id);
let temp: User[] = _omit(state.data, position);
temp.splice(num, 0, test); //This function outright fails to execute
const newState = {
...state,
usersData: temp
}
return newState;
}
I am curious if there are more efficient ways to approach this situation?