I am trying to reach the Promise result in a Reactjs function component, but it does not work for me. When I return the function result I only get Promise. My goal is to return an object contained in [[Promise Result]].
const params = ['ACT', 'STBY', 'STBYH'];
const getActStby = async address => {
const getActStbyParams = await getXhr({
url: `./scripts/system_read_config?${xhrParam(address, params)}`
});
return getActStbyParams;
};
Then I call It later in a code and assigning to the object as a new property:
newItemEqpt.isAct = getActStby(getNetworkAddress(item.from.FROM, item.to.TO));
Output of these activities is "partially" okay. When I console.log the object, Promise is fulfilled, but what I wanted to is assigning the array of parameters in [[Promise result]] directly to isAct property. How can I do this?
isAct: Promise
[[Prototype]]: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: Object
parameters: (3) [{…}, {…}, {…}]
[[Prototype]]: Object
The function getActStby declared as async, so you have to await for getting its results like so;
newItemEqpt.isAct = await getActStby(getNetworkAddress(item.from.FROM, item.to.TO));
To be able to use the await keyword like above, the function call to getActStby should also be made in an async function, otherwise you will have to chain the function with a then method and access the return value of that function by using a callback.