Search code examples
reactjsreact-nativereduxredux-saga

Action get dispatched but nothing happen


I'm trying get data from action payload to use in redux-saga but it return undefined

Here is some code

Action

export const GetUserInfo = (user, password) => {
    return{
        type: actionList.GET_USER_INFO,
        data: {user, password},
    }
};

Saga part

LoginSaga

function* loginSaga(action) {

    console.log('Saga is working')
    const getJson = yield call(requestGetUser)
    const getJsonData = getJson

    const getJsonUsername = String(getJsonData.username)
    console.log(getJson)
    console.log('getjson data ', getJsonUsername)
    console.log(action.data.username) // try to get data but return undefined

    const getJsonPassword = String(getJsonData.password)

    if (String(action.data.username) === getJsonUsername) {
        if (String(action.data.password) === getJsonPassword) {
            console.log('saga login success')
            yield put({type: 'LOGIN_SUCCESS'})
            SaveToAsyncStorage(action.data)
        }
        else {
            console.log('saga password fail')
        }
    }
    else {
        console.log("saga user fail")
    }
}
export {loginSaga}

WatchSaga

export function* watchSaga() {
    yield takeLatest(GET_USER_INFO,loginSaga);
}

Main file use useDispatch(username,password) to store these data, it show in redux extension, but return undefined Here is a gif to show what going on

Thank a lot

enter image description here


Solution

  • I have close look at the repo provided by you there is a mistake you must have to do some changes as below;

    replace the below code:

    export const GetUserInfo = (user, password) => {
        return{
            type: actionList.GET_USER_INFO,
            data: {user, password},
        }
    };
    

    WITH THE BELOW CODE

    export const GetUserInfo = (username, password) => {
        return{
            type: actionList.GET_USER_INFO,
            data: {username, password},
        }
    }; 
    

    Reason is you are trying to get the username property from the action but the return property is user.