Skip to content

how can i call another dispatch when first dispatch done? #3535

Answered by ramarivera
giovannidias1 asked this question in Q&A
Discussion options

You must be logged in to vote

Assuming that "sending" a question ends up being an API call (or some "long" running process), you could have an effect listening to sendAnswer, and when it finishes processing it (whatever that means in your context), then this effect would dispatch another action e.g. answerSent.

You could then do something like

this.store.dispatch(sendAnswer({ answer: data }));

this.store.select(someSelectorThatReadsThatDataWasUpdatedBasedOnYourAnswer(data)).
               .pipe(take(1))
               .subscribe(() => { 
                    this.store.dispatch(loadQuestion({ slug: this.slug, take: 5 }));
               });

Not claiming it's the best way, just a way

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by giovannidias1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants