I am creating an SPFx webpart for SharePoint Online. I use this code. It does write values to the console (all the email addresses of the people in the group) but it doesn't return the 'stringToReturn' value to display in the web part.
My web part displays: Meet the Team... undefined
Am I doing something fundamentally wrong?
Thanks P
public async render(): Promise<void> {
this.domElement.innerHTML = `
<section>
<div>
Meet the Team...
</div>
<div>
${await this.getGroupData()}
</div>
</section>`;
}
protected async getGroupData(): Promise<string>
{
let stringToReturn:string;
try
{
this.context.msGraphClientFactory.getClient('3')
.then((client: MSGraphClientV3): void => {
client.api('groups/<GUID>/members')
.get((error: any, response: any, rawResponse?: any) => {
const members: MicrosoftGraph.User[] = response.value;
for (const memberDetail of members){
console.log('memberDetail.mail:' + memberDetail.mail);
stringToReturn = memberDetail.mail + "<br>";
}
});
});
}catch(e){
stringToReturn = e.message.toString();
}