mikenlanggio
mikenlanggio

Reputation: 1137

What difference between select and without select in NgRx?

I have two ways usually use when I subscribe to a state of a store. Is it any difference between them (like performance or something)

constructor(private store : Store<MyState>){
    //1
    this.store.pipe(select(x=>x.myComplexObject)).subscribe(x=> {
        this.data = x;
    })
    //2
    this.store.subscribe(x=> {
        this.data = x.myComplexObject;
    })
}

Upvotes: 0

Views: 86

Answers (1)

timdeschryver
timdeschryver

Reputation: 15525

Both are the same. But, I would suggest moving to selectors because these have several advantages:

  • multiple selectors can be combined
  • easy to test
  • performant because it's memoized

https://ngrx.io/guide/store/selectors

Upvotes: 2

Related Questions