Answer the question
In order to leave comments, you need to log in
Why is redux-saga not working?
Hey! Everything seems to be simple:
const getAccounts = function* getAccounts() {
while (true) {
const request = yield take(GET_ACCOUNTS);
const userID = request.data.userID;
try {
response = yield call(AccountsService.getAccounts, userID); // тут асинхронный вызов
yield put({ type: ACCOUNTS_RECEIVED, response });
} catch (error) {
return false;
}
}
}
export const accounts = (state = INITIAL_STATE, action) => {
switch (action.type) {
case ACCOUNTS_RECEIVED:
console.log(action); // тут action.response - undefined
return { ...state, accounts: action.response.Items[0].accounts };
case ADD_ACCOUNT:
return { ...state, accounts: [ ...state.accounts, action.newAccount ] };
default:
return state;
}
};
Answer the question
In order to leave comments, you need to log in
You have an error here:
export const getAccounts = (userID) => {
fetch(`${BASE_URL}/users/${userID}/accounts/`).then(resp => {
resp.json().then(accounts => accounts.Items[0].accounts);
})
}
export const getAccounts = userID =>
fetch(`${BASE_URL}/users/${userID}/accounts/`).then(resp => {
resp.json().then(accounts => accounts.Items[0].accounts);
});
response = yield call(getAccounts, userID);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question