我正在尝试构建一个组件,该组件从 Amazon AWS/Amplify 检索完整的用户列表,并通过映射函数在表格中显示所述结果。到目前为止一切都很好。
但是,对于第 4 列,我需要调用第二个函数来检查用户是否属于任何组。我已经将该功能作为按钮/onClick 事件进行了测试 - 它可以工作(console.logging 输出)。但是在渲染表数据时直接调用它不会返回任何东西。
这是我在 return 语句中包含的内容(在 map 函数中)
<td>={getUserGroups(user.email)}</td>
然后调用此函数:
const getUserGroups = async (user) => {
const userGroup = await cognitoIdentityServiceProvider.adminListGroupsForUser(
{
UserPoolId: '**Removed**',
Username: user,
},
(err, data) => {
if (!data.Groups.length) {
return 'No';
} else {
return 'Yes';
}
}
);
};
任何人都可以建议吗?非常感谢提前!