Search code examples
angulartypescriptngrx

What is the difference when using feature state or root state for the store in a component?


When using the store inside a component, what's the difference between the options:

A) constructor(private store: Store<AppState>) {}
B) constructor(private store: Store<FeatureState>) {}

It seems like there is no difference between these two options. No matter if I'm dispatching actions for either states or even selecting AppState or FeatureState. It works no matter what. The question is, what state should I put inside <>?


Solution

  • There is no difference, in both cases you'll receive the whole store state at run time.

    The only difference is your state is typed, but if you use selectors this has no benefits as the selectors are typed themselves.

    I would encourage to just use Store<any>.