Search code examples
reduxdesign-patternsngrx

[Redux/Ngrx][Design-pattern][Good practise] Do a get after each update/delete?


I'm faced with a problem for which I couldn't find documentation on good practise.

I have a list of items which can be updated or deleted and I'm using a store to manage it.

When updating/deleting an item, should I remove it from the store's list on backend sucessfull response, or should I do a full get to populate my store with the actualised list ?

If you have some pertinents links for me I'm all ears :)

Thanks !


Solution

  • It depends, you can:

    • remove from store, do the request, and rollback if the request has failed. This might make your application feel faster because you don't need to wait for the response
    • make the request, and remove from the store when successful. I think this is the most common.
    • make the request, and refresh the whole list. This is also OK to do, but might be slower for large or complex lists, but on the other hand it refreshes your state. This might be useful if multiple users are using the application. Here are also two variations, the request might return the new list, or you can refetch the data in a second request.