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

268
Views
How to make other function gets called after first is executed?

I am working on a react app where I am using redux for state management and I have 2 functions to call and I want them to run only after 1st function is executed.

Here's a snippet of whats I am doing:

if (this.props.page_num < this.props.numPages) {
       this.props.fetchCode(params, isFiltered, isSearched).then(() => {
          this.props.setPageNumber(this.props.page_num + 1);
        });
      }

Here I am getting a error stating:

CodeTable.jsx?2468:132 Uncaught TypeError: this.props.fetchCode(...).then is not a function

fetchCode function:

export function* fetchCode(action) {
  try {
    const response = yield call(Services.fetchCode, action.params);
    const { dtoList } = response.data.pagedList;
    const num_pages = response.data.pagedList.numPages;
    const total_records = response.data.pagedList.totalRecords;
    const page_number = response.data.pagedList.pageNumber;
    const postCodeSetsData = dtoList.map(({
    }) => ({
    }));
    yield put(ActionCreator.setCodes(dtoList, num_pages, total_records, postCodeData, page_number, action.isFiltered, action.isSearched));
  } catch (error) {
    sagaException(error);
  }
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Since you are using redux saga, I believe the most appropriate thing to do is compose another saga.

export function* fetchCodeSetsAndSetPage(action) {
  try {
    yield put (ActionCreator.fetchCodes(...));
    yield put (ActionCreator.setPageNumber(...));
  } catch (error) {
    sagaException(error);
  }
}

And then call that one instead in your component.

Some docs.

about 4 years ago · Juan Pablo Isaza Report

0

make fetchCodeSets function async. You can write promise like then only with an async functions. also use a return statement inside the function. The declaration of the fetchCodeSets function should be like this

const fetchCodeSets = async (params) => {
    //codes here
    return;
}
about 4 years ago · Juan Pablo Isaza Report
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!