Skip to content

useReducer dispatch flow clarification #2017

Description

@NicolasRannou

Hi,

I've been looking around to try to find out more about the "dispatch / render" flow and can not find anything relevant yet.

My question is: when I do 2 dispatchsequentially such as:

dispatch({type: ACTION_1});
dispatch({type: ACTION_2});

Are we sure that the 2 actions will be processed before the next rendering cycle occurs?
Could it be that on the next rendering cycle, only ACTION_1 has been processed then ACTION_2 is processed on a later rendering cycle?

In other words, from the react perspective, is doing:

dispatch({type: ACTION_1});
dispatch({type: ACTION_2});

equivalent to:

dispatch({type: ACTIONS: payload: [ACTION_1, ACTION2]});

In a small demo, it seems that it doesn't matter:
https://codesandbox.io/s/tzp0s (see the console messages)

In my larger react app, it seems that often time there is a render cycle between 2 consecutive dispatch.

Is it considered an anti-pattern to do 2 dispatch sequentially and should we instead do 1 dispatch with the content of the 2 dispatch combined?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions