Issue
I need the effect to run twice. One in the SSR and another in the browser but this is not happening it calls the effect of success but does not call the API
my component calls
constructor(
private store: Store<IViewQuestionState>,
private route: ActivatedRoute,
private metaService: MetaSeoService,
@Inject(PLATFORM_ID) platformId: Object
) {
this.route.params.subscribe(params => {
this.slug = params['slug'] as string;
this.store.dispatch(loadQuestion({ slug: this.slug, take: this.take }));
});
this.isBrowser = isPlatformBrowser(platformId);
if (this.isBrowser) {
this.store.dispatch(loadQuestion({ slug: this.slug, take: this.take }));
this.getQuestion();
}
}
My effect
loadQuestionBySlug$ = createEffect(() =>
this.actions$.pipe(
ofType('[View Question Component] load question'),
mergeMap((actions: any) => {
return this.questionsService
.getBySlugQuestions(actions.slug, actions.take)
.pipe(
map((question: any) => loadQuestionSuccess({ question })),
catchError(err => [loadQuestionFailure(err)])
);
})
)
);
when I put an alert() in mergeMap the call works but the first one in SSR doesn't work
Solution
I found the problem, the problem are in BrowserTransferStateModule, i add param different everytime when make the call
like this answer: https://stackoverflow.com/a/57177518/3140824
Answered By - Giovanni Dias
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.