I'm trying to assign a variable inside a .then
function but I don't know how to do that in svelte store. I know that its a promise and takes some time to be assigned.
Here is the code.
The map function
data.products.data = data?.products?.data?.map((item) => {
let category = '';
customPIMListStore.getProductCategory(item.productCategoryId, token).then((data) => {
category = data;
console.log('category inside', category);
});
return {
...item,
category
};
});
The other function to get the category:
getProductCategory: async (id, token) => {
const res = await api.get(`backoffice/v1/category/${id}`, token);
return res?.category?.name;
},