Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
How can I use redux saga function action inside getServerSideProps function of nextjs

in next.js, i want to operate the saga function inside getServerSideProps, it is dispatched to the serverSide store, but there is a problem that it is not shared to the client store when the hydrate action is executed. My guess is that rehydrate runs before takeEvery runs, is it a version issue?

I want to move the asynchronous logic to sagaFunction and handle it.

it's my code

//saga.ts
export function* getProductDetailSaga({ payload }: ReturnType<typeof getProductDetailAction>) {
  try {
    const { data } = yield* call(getProductDetail, payload);
    yield put(setFetchedProductDetails(data.productDetail));
  } catch (error) {
    console.error(error);
  }
}

export default function* productDetailSaga() {
  yield all([
    takeEvery(getProductDetailAction.type, getProductDetailSaga),
}

//[productId].tsx
export const getServerSideProps = wrapper.getServerSideProps((store) => async (ctx) => {
  const { productId } = ctx.query;
  const {
    osCode,
    deviceId,
    session,
  } = store.getState().user;

  store.dispatch(
    getProductDetailAction({
      osCode,
      deviceId,
      session,
      productId,
    })
  );

  store.dispatch(END);
  await store.sagaTask.toPromise();
});

i think END action and sagaTask are not functioning properly.

but this works fine.

export const getServerSideProps = wrapper.getServerSideProps((store) => async (ctx) => {
  const { productId } = ctx.query;
  const { osCode, deviceId, session } = store.getState().user;
  const { data } = await getProductDetail({
      osCode,
      deviceId,
      session,
      productId,
    });
  
store.dispatch(setFetchedProductDetails(data.productDetail || null));
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!