我正在使用 Reaml、Apollo Client 和 React.js 教程关注任务跟踪器(Web), 并且我正在获取用户项目。下面是我的代码
export default function TaskApp() {
const app = useRealmApp();
console.log(app.currentUser.customData)
const [currentProject, setCurrentProject] = React.useState(
// set the current project as "My Project"
app.currentUser.customData.memberOf[0]
);
const [isEditingPermissions, setIsEditingPermissions] = React.useState(false);
return (
<Container>
<Sidebar
css={gridAreaSidebar}
currentProject={currentProject}
setCurrentProject={setCurrentProject}
setIsEditingPermissions={setIsEditingPermissions}
></Sidebar>
<ProjectScreen
css={gridAreaMain}
currentProject={currentProject}
isEditingPermissions={isEditingPermissions}
setIsEditingPermissions={setIsEditingPermissions}
/>
</Container>
);
}
以下是出现的错误,我不明白为什么会出现错误
TypeError: Cannot read properties of undefined (reading '0')
TaskApp
E:/Web Dev/Realm/realm-tutorial-web/src/TaskApp.js:13
10 | console.log(app.currentUser.customData)
11 | const [currentProject, setCurrentProject] = React.useState(
12 | // set the current project as "My Project"
> 13 | app.currentUser.customData.memberOf[0]
| ^ 14 | );
15 | const [isEditingPermissions, setIsEditingPermissions] = React.useState(false);
16 | return (
我还是新手,所以请尽可能提供帮助。