Search code examples
ngrxngrx-effects

Why @ngrx/effects trigger action but doesn't change the state?


I have this effect:

loadIpInfo$ = createEffect(() => {
    return this.actions$.pipe(
        ofType(loadIpInfo),
        concatMap((action: {ipInfoConfig: IpInfoConfig}) => {
            return this.ipService.getIpDetails(action.ipInfoConfig).pipe(
                map((ipInfoResponse) => {
                    this.store.dispatch(setErrorMessage({ message: '' }));
                    return loadIpInfoSuccess({ ipInfoResponse });
                }),
                catchError(() => {
                    return of(setErrorMessage({ message: 'Unknown error occurred. Please try again' }));
                })
            )
        })
    )
})

It triggers the action: loadIpInfo but doesn't change the state.

Action

State

Using breakpoints I saw that it didn't enter concatMap.

I've tried with different rxjs.operators such as: exhaustMap, mergeMap, switchMap but with the same result.

The purpose of this effect is to get static data from the config.json and call a httpClient.get(..) with this information.

What am I doing wrong?


Solution

  • Hard to say without having a reproduction.

    Make sure to import the effects class in EffectsModule.forRoot([]) or EffectsModule.forFeature([]).