I'm having a hard time to debug this cause I'm not sure if my approach is correct.. once I do some request the my action call returns me undefined action and simply not pushing my object on my redux store.
// here's my store
const initialState = {
store: {}
}
const reducer = (state = initialState, action) => {
switch (action.type) {
case 'GET_DB':
return {
...state,
store: action.payload
}
case 'ADD_SUPPLIER':
return {
...state,
store: {
...state.store,
supplier: [
...state.store.supplier,
{
supplier_name: action.payload.supplier_name,
address: action.payload.address,
contact_person: action.payload.contact_person,
contact_number: action.payload.contact_number,
note: action.payload.note
}
]
}
}
default:
return state;
}
}
export default reducer;
// here's my dispatch
const [supplier, setSupplier] = useState({
_id: Localstorage?.result?._id,
token: Localstorage?.token,
supplier_name: '',
address: '',
contact_person: '',
contact_number: '',
note: ''
});
dispatch(add_supplier(supplier));
export const add_supplier = (supplier) => async (dispatch) => {
try {
const { data } = await api.add_supplier(supplier);
dispatch({ type: 'ADD_SUPPLIER', payload: data });
} catch (error) {
console.log({ 'error': error });
}
}
I'm quite sure there's something wrong with my approach can someone please correct it cause im a newbie on redux. thanks