Skip to content

Valid to dispatch multiple actions from an event handler? #797

@bfink13

Description

@bfink13

I'm in a situation where I'd like to dispatch two actions when a text box is blurred - I want to mark it as "touched" and also save it if there are no validation errors. I keep track of validation in the "change" reducer and only show the error message if a box has been "touched". I only want to save if there are no errors:

var item = this.props.items[index];
if (!item.error) {
    this.actionCreators.saveItem(item.name, item.value);
}

this.actionCreators.touchItem(item.name);

I'm using API middleware similar to the Real World example. It doesn't seem right to dispatch multiple actions in a single event handler since the second action will be working with state that is out of date.

I feel like I'm missing something simple, as this seems to be a pretty common scenario.

Does anyone have recommendations?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions