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

110
Views
Variable keeps returning a function when used inside another variable
const getPatientProceduresID = createAsyncThunk(
  "selectedPatient/getPatientProcedures",
  async (arg, { getState }) => {
    const state = getState();
    const patient = state.selectedPatient.patient;
    const token = state.userDetails.token;

    try {
      const apiUrl = process.env.REACT_APP_API_URL;

      var config = {
        method: "get",
        url: `${apiUrl}/GetProcedures/${patient}`,
        headers: {
          accept: "application/json",
          "Authorization-Token": token,
        },
      };

      const response = await axios(config);
      const data = await response.data;

      return data[0].id;
    } catch (error) {
      console.log(error);
    }
  }
);

export const getPatientProcedureDetails = createAsyncThunk(
  "selectedPatient/getPatientProcedureDetails",
  async (arg, { getState }) => {
    const state = getState();
    const patientID = state.selectedPatient.patient;
    const procedureID = getPatientProceduresID;

    console.log(procedureID());

    const token = state.userDetails.token;

    try {
      const apiUrl = process.env.REACT_APP_API_URL;
      

      var config = {
        method: "get",
        url: `${apiUrl}/GetProcedureDetail/${patientID}/${procedureID}`,
        
        headers: {
          accept: "application/json",
          "Authorization-Token": token,
        },
      };

      const response = await axios(config);
      const data = await response.data;
      return data;
    } catch (error) {
      console.log(error);
    }
  }
);

When I console.log procedureID, it returns the whole function instead of the result. What am I doing wrong? I need to use the result of the first variable in the second, because it contains the procedure id that I need for "${apiUrl}/GetProcedureDetail/${patientID}/${procedureID}"

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are assigning the function getPatientProceduresID to the variable procedureID without execution. Also, it is an asyncThunk, so you'd need to dispatch it - and if you directly want the result also need to unwrap it. So:

const procedureID = dispatch(getPatientProceduresID()).unwrap();

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!