Platform: Error: Effect "<some effect>" dispatched an invalid action: undefined

Created on 25 Feb 2018  路  1Comment  路  Source: ngrx/platform

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[*] Bug report  
[ ] Feature request
[ ] Documentation issue or request

What is the current behavior?

When trying to dispatch an action on ngInit, I am getting the following error messages:
Error: Effect "UserEffects.fetchUser$" dispatched an invalid action: undefined and TypeError: Actions must be objects after the dispatched action and the associated effect as executed.

Most helpful comment

To help those landing here from google, you probably returned store.dispatch(action) in your effect instead of simply the action, for example...

bad

@Effect()
  loginSuccess$ = this.actions$.pipe(
    ofType(UserApiActionTypes.LoginSuccess),
    switchMap(_ => this.store$.select(fromAuth.getRedirectUrl)),
    map(url => this.store$.dispatch(new routerActions.Go(url)))
  );

good

@Effect()
  loginSuccess$ = this.actions$.pipe(
    ofType(UserApiActionTypes.LoginSuccess),
    switchMap(_ => this.store$.select(fromAuth.getRedirectUrl)),
    map(url => new routerActions.Go(url)) /* this is the changed line */
  );

>All comments

To help those landing here from google, you probably returned store.dispatch(action) in your effect instead of simply the action, for example...

bad

@Effect()
  loginSuccess$ = this.actions$.pipe(
    ofType(UserApiActionTypes.LoginSuccess),
    switchMap(_ => this.store$.select(fromAuth.getRedirectUrl)),
    map(url => this.store$.dispatch(new routerActions.Go(url)))
  );

good

@Effect()
  loginSuccess$ = this.actions$.pipe(
    ofType(UserApiActionTypes.LoginSuccess),
    switchMap(_ => this.store$.select(fromAuth.getRedirectUrl)),
    map(url => new routerActions.Go(url)) /* this is the changed line */
  );
Was this page helpful?
0 / 5 - 0 ratings