Does ngrx selectors gets called once on initial load

817 Views Asked by At

It it normal for a ngrx selector to have an emitted value despite no action is dispatched at all?

This console.log runs here even if no actions are dispatched in my app

this.bookmarks$ = this.store.pipe(
  select(fromBookmarks.selectBookmarks),
  tap(_ => console.log('fetch bookmarks'))
);

Would it be okay to skip(1) the first emission or it's kinda hacky.

1

There are 1 best solutions below

1
On

Yes, the selectors and actions independent: selectors query the state, and reducers listen to actions in order to update the state. So:

  • There is always a state, a initial state when app starts ==> selector will always return a value
  • Actions will not always make changes to state, they can be ignored by reducers.