Hi,
My return value from function is empty.
I check the var value before it returns from the function and the value is set, but after the function returns the value is empty..
The function:
async function isFollow (follower,followee) { let x; x = await wixData.query("follow").eq("followee", followee).and(wixData.query("follow").eq("follower", follower)).find().then( (results, y) => { if(results.items.length > 0){ return true; }else{ return false; } }); console.log(x) // value is true/false return x; }
The function call:
var res; res = isFollow(follower, followee); console.log(res); // value is empty!!! if(res){ $item("#follow").label = "Following"; }else{ $item("#follow").label = "Follow"; }
Hi, Your isFollow function is async, so you need to await the results. As an example, you can make it inside the onReady function:
$w.onReady(async function () { let res; res = await isFollow(); console.log(res); // value will be correct! });