N
N
Nikita2018-04-22 17:18:22
React
Nikita, 2018-04-22 17:18:22

Why is only the last dispatch executed?

Good day!
There was a problem with redax, before that I didn’t work with it at all.
I have a state in which the authorization state is stored and a state in which the user data is stored.
During the authorization process, when I try to get an updated state from the store, I only have the last dispatch, what could be the matter?
The authorization check method itself:

authStatus = (response) => {
        if (response.message === "Success" || response.message === "Already login") {
            this.props.loginState(true);
            this.props.setUserData(response.result);
        } else {
            this.setState({
                isOpenModalSignin: true
            });
            this.props.loginState(false);
        }
    };

And connect:
connect(
    state => ({
        isLogin: state.isLogin,
        userData: {
            userName: state.userName,
            email: state.email,
            id: state.id
        }
    }),
    dispatch => ({
        loginState: (loginState) => {
            dispatch({
                type: "IS_AUTH",
                payload: loginState
            })
        },
        setUserData: (userData) => {
            dispatch({
                    type: "USER_DATA",
                    payload: userData
                }
            );
        }
    })

Actually, if I execute setUserData last, then loginState is not executed, but returns undefined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2018-04-23
@maxfarseer

I don't see any problems with connect. Look further down the chain. Could it be the reducer?
Is the IS_AUTH action in the logger or is redux_dev_tools visible?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question