Answer the question
In order to leave comments, you need to log in
Is redux-saga compiled correctly?
saga.js:
import { call, put, takeLatest } from 'redux-saga/effects'
function* fetchUser(action) {
try {
const query = yield call(async () => {
/*
больше всего интересует именно call, изначально было написано так:
const query = yield call(() => {
return fetch('https://api.themoviedb.org/3/movie/top_rated?api_key=<<api_key>>&language=ru&page=1')
.then(response => response.json())
.then(result => result);
});
потом VSCode предложил сделать автозамену, и получилось то что ниже.
Мне кажется это бред, ведь сага и так асинхронно выполняется, верно?
*/
const response = await fetch('https://api.themoviedb.org/3/movie/top_rated?api_key=<<api_key>>&language=ru&page=1');
const result = await response.json();
return result;
});
yield put({ type: "USER_FETCH_SUCCEEDED", result: query });
} catch (e) {
yield put({ type: "USER_FETCH_FAILED", message: e.message });
}
}
function* saga() {
yield takeLatest("USER_FETCH_REQUESTED", fetchUser);
}
export default saga;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question