Answer the question
In order to leave comments, you need to log in
How to pass data (payload) to redux-saga?
Hello.
There is an example from documentation:
export function* incrementAsync() {
yield delay(1000)
yield put({ type: 'INCREMENT' })
}
export function* watchIncrementAsync() {
yield takeEvery('INCREMENT_ASYNC', incrementAsync)
}
Answer the question
In order to leave comments, you need to log in
A simple query example:
export function* fetchPostBySlugSaga({ payload: { slug } }) {
try {
const data = yield call(Api.fetchPostBySlug, slug);
yield put(fetchPostBySlugSucceeded(data));
} catch (error) {
yield put(fetchPostBySlugFailed(error));
}
}
export default function* watchFetchPostBySlugSaga() {
yield takeLatest(FETCH_POST_BY_SLUG, fetchPostBySlugSaga);
}
export function fetchPostBySlug(slug) {
return {
type: FETCH_POST_BY_SLUG,
payload: {
slug,
},
};
}
export function fetchPostBySlugSucceeded(data) {
return {
type: FETCH_POST_BY_SLUG_SUCCEEDED,
payload: {
data,
},
};
}
export function fetchPostBySlugFailded(error) {
return {
type: FETCH_POST_BY_SLUG_FAILED,
payload: {
error,
},
};
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question