Skip to content

How to handle Async responses when route is changed? #1619

@pratishshr

Description

@pratishshr

In my CRUD app, I am using same form component and same state for the form in redux for add and edit. When I call the API for fetching data using Promises for edit and before the response arrives, we change our route to "Add" form, all the form data will be auto filled for add item since i am using the same state for both add and edit. Is there any way to prevent this from happening?

my action creator:

fetchById: function (entity, id) {
        return function (dispatch) {
            dispatch(apiActions.apiRequest(entity));
            return (apiUtil.fetchById(entity, id).then(function (response) {
                    dispatch(apiActions.apiResponse(entity));
                    dispatch(actions.selectItem(entity, response.body));
            } 
       }
}

As response is late, "selectItem" is dispatched late. And when I open form for adding item, this form is filled with the data from response.

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