I'm learning ngrx/store and I have a component that call to a service to get some data from the server, as I refactor it to use ngrx/store, I don't know where to update the store.
As I understand I have 2 options:
dispatch
to update to store.dispatch
. The component can subscribe to that part of the state (using select
) and when the service will get the data and update the state, the component will get the update through the store subscription.Which is the right ("Best Practice") way to go? (Maybe there is another why I should do this?)
NgRx is a global state management library that helps decouple the Domain and Business layers from the Rendering layer. It's fully reactive. All changes can be listened to using simple Observables, which makes complex business scenarios easier to handle.
NgRx Store provides reactive state management for Angular apps inspired by Redux. Unify the events in your application and derive state using RxJS.
You should do it using @ngrx/effects.
This is the best practice.
See my repo for examples of using effects.
Memroy Game (with effects)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With