When you need to add data into an application from a http request, I heard its good practice to:
- dispatch an action, which activates an
@Effect
. @Effect
fetches data from ahttp
request.- This then fires off another action
- Which then finally updates the store.
The rationale behind this is because a http call is a side effect, and thus should be handled by the @ngrx/effects
library.
Is this good? I find this problematic because once the first action is dispatched, I have no idea if its successful or a failure. The only way I would know is if my State
has an "hasErrorHappened" property or something similar. And I do not believe having such property is a good thing
Or is it better to:
- Create a service which does the
http
call, which gets the data - Update the store after the service with that data