Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Redux TS Error Actions must be plain objects. Instead, the actual type was: 'Promise'

I am getting this error with TS and Redux and cant figure it out why it happens and how its could be fixed.
I am using redux thunk middleware.
Redux TS Error Actions must be plain objects. Instead, the actual type was: ‘Promise’.

Seems that issue starts to happen in updateUserSession(data)

which gets started this way:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  insertUserSession(data)
                                .then(
                                    (res: IUserSession) => {
                                        updateUserSession(data)
                                    },
                                    err => {
                                        console.error("Insert session failed", err)
                                    },
                                )
                                .then(() => {
                                    //Here will continue another async action
                                })


    export const insertUserSession = (session: IUserSession): Promise<IUserSession> => {
    return axios.post("/user/" + session?.userId + "/session", session)
}
export const updateUserSession = (data: IUserSession) => {
    return axios.put('/user/' + data.userId + '/session', data)
        .then(
            (response) => {
                 fetchUserSession(store.getState().user?.userData?.username)
                    .then(
                        (res) => {
                            if (typeof res.data === "object" && !Object.keys(res.data).length)
                                 saveUserSession(res.data)
                         
                        },
                        (err) => {
                            console.error(err);
                        },
                    )
            },
            (err) => {
                console.error(err);
            },
        )
}

export const saveUserSession = (data: IUserSession) => {
    return (dispatch: Dispatch<UserAction>) => {
        dispatch({
            type: UserType.SAVE_USER_SESSION,
            payload: data,
        });
    }

}

>Solution :

This is happening because updateUserSession is actually a thunk and not an action. It seems saveUserSession is the action you need to call with callback data.

Be sure to declare the correct thunk signature:

const updateUserSession = (data: IUserSession) => (dispatch, getState) => {}

Also, don’t forget to call dispatch to fire actions inside the thunk.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading