How to dispatch multiple actions one after another

前端 未结 3 1740
借酒劲吻你
借酒劲吻你 2021-02-05 05:19

In my react / redux application I often want to dispatch multiple actions after another.

Given the following example: After a successful login I want to store the user d

3条回答
  •  囚心锁ツ
    2021-02-05 05:56

    Yes redux-thunk allows you to do as you say, and yes it is a best practice for dispatching multiple actions (one that I prefer over the alternatives because of it's simplicity). The state is indeed updated as soon as you dispatch (by the time it returns), which is why you are given a function to retrieve the state in a thunk, instead of simply a reference to the state. In that way you can alter the state with one dispatch, and then call getState() to get a reference to the new state to read from if you need to.

提交回复
热议问题