reactjs - i am not able to show new user address in redux saga -


i working on react/redux e-commerce project, making functionality of adding user address, functionality working fine, able add new user address, problem have refresh page show new address card, address card not showing after saving address, have refresh page show new address, can solve issue, actions, reducers , saga file attached below

action file

const addaddressbybuyerid = (address: object, params: string) => ({     type: types.add_address_by_buyer_id,     address,     params, }); const addaddressbybuyeridsuccess = (addresses: object, params: string) => ({     type: types.add_address_by_buyer_id_success,     addresses,     params, }); const addaddressbybuyeridfailure = (errormessage: object) => ({     type: types.add_address_by_buyer_id_failure,     errormessage, }); 

saga file

function* addaddressbybuyerid(action) {         try {             const response = yield call(api.account.postaddressbybuyerid, action.address);             if (response.ok && response.data && {}.hasownproperty.call(response.data, 'data')) {                 yield put(actions.getaddressesbybuyerid());                 yield put(actions.addaddressbybuyeridsuccess(response.data.data));             } else {                 yield put(actions.addaddressbybuyeridfailure(response.errormessage));             }         } catch (error) {             yield put(actions.addaddressbybuyeridfailure());         }     }     function* watchaddaddressbybuyerid(): generator<void, void, void> {         yield takelatest(types.add_address_by_buyer_id, addaddressbybuyerid);     } 

reducers file

export const addaddressbybuyerid = (state: object = initial_state) => ({     ...state,     isloading: true,     successmessage: null,     errormessage: null, });  export const addaddressbybuyeridsuccess = (state: object = initial_state, action: object) => {     const successmessage = i18n.gettext('account.address-added', {}, 'address added!');     return {         ...state,         address: action.address,         isloading: false,         successmessage,     }; };  export const addaddressbybuyeridfailure = (state: object = initial_state, action: object) => ({     ...state,     errormessage: action.errormessage || genericerror,     isloading: false, }); 

you have typo.

in action file return object contains addresses property (see addaddressbybuyeridsuccess function).

however in reducer (addaddressbybuyeridsuccess) accessing address property undefined.


Comments