I cannot figure out why this function does not return data when it is called. The data is returned in the function itself however. This is probably a simple thing that I am overlooking.
export function returnMemberData ( email )
{
wixData . query ( “Members/PrivateMembersData” )
. eq ( “loginEmail” , email )
. limit ( 1000 )
. find ()
. then ( results => {
if ( results . items . length > 0 )
{
console . log ( “Results found” )
const myResults = results . items [ 0 ];
//console.log("MyResults: " + myResults.firstName)
**const** myUser = { firstName : myResults . firstName ,
lastName : myResults . lastName
}
console . log ( "MyUser: " + myUser . firstName )
return myUser
}
else
{
console . log ( “No Results” )
}
})
. catch ( ( err ) => {
let errorMsg = err ;
console . log ( "Error: " + errorMsg )
} );
}
Now from within my program, I enter this:
var obj = returnMemberData ( “len@perroots.com” )
console . log ( "First Name: " + obj . firstName )
firstName is underlined in red with a message: Property ‘firstName’ does not exist on type ‘void’
And when I run the program in Preview, I get this error in console:
TypeError: Cannot read property ‘firstName’ of undefined
What am I doing wrong? Thanks