I have an API call I am making:
function createReferral(referralData: { actionTypeId: number }) {
referralAxios.post(`/api/ReferralMasters`, {
appTypeID: referralData.appTypeId,
}).then(function (response) {
console.log(actionTypeId)
})
}
I am getting an error message saying that actionTypeId
is not defined.
How do I go about passing my function parameter to the .then
part of the API call?
3
Answers
The attribute
actionTypeId
is a part of thereferralData
object and therefore not visible to thethen
function. Try to print it the following way instead:You have to get that value from
referralData
:Your parameter description does not desctructure
actionTypeId
from parameters.If you would like to destructure, this is the way to do it.
However, if you would like to simplify, it’s best not to destructure, and use interfaces/types for type definition.