I3artosz
I3artosz

Reputation: 123

How to dispatch an action when another becomes fulfilled with reduxjs/toolkit React and Typescript?

When user is signing up. After form is submitted i want to dispatch authUser action. But i need to wait until signUp action is finished. How i can achieve that?

I've tried to dispatch one action after another but both actions are async, so they are performed simultaneously.

Upvotes: 3

Views: 2129

Answers (1)

I3artosz
I3artosz

Reputation: 123

I'm not sure if this is the best way of doing this but i found working solution.

   dispatch(first)
        .unwrap()
        .then(() => dispatch(second).unwrap());
    }}

Upvotes: 1

Related Questions