Return a value from one function to another function

Is there any way to return this value inside a function to another function?

Thanks in advance

1 Like

call the function as the parameter value

I’m not sure we have enough information to give you a good answer. If both of those functions need access to the ids then the code needs to be structured in a way that they can both access it. Can you pass ids into handleModalDesitionConfirm like you are for handleStatusChange?

But ya, you can’t define getIds inside of handleStatusChange and then expect to access it in another function. I’m not sure I understand what the point of getIds is since it’s just returning the same value passed into handleStatusChange. Again, if ids can be passed into handleStatusChange then can it also be passed into the other function?

Put it in a different function or object. For example:

function idStore() {
  let id = "";
  return {
    getId: () => id,
    setId: (newId) => {
      id = newId;
    }
  }
}

Or

class IdStore {
  #currentId = "";

  set id(newId) {
    this.#currentId = newId;
  }
  get id() {
    return this.#currentId;
  }
}

Then use that. Note that both of the above are done that way to ensure that when you get the ID it’s the value you want.