fix: usePage hook throws an error without projectId (#3827)

This commit is contained in:
Aaryan Khandelwal 2024-02-28 19:14:15 +05:30 committed by GitHub
parent 0215b697a5
commit c4028efd71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,13 +9,13 @@ export const usePage = (pageId: string) => {
const { projectPageMap, projectArchivedPageMap } = context.projectPages;
const { projectId, workspaceSlug } = context.app.router;
if (!projectId || !workspaceSlug) throw new Error("usePage must be used within ProjectProvider");
if (projectPageMap[projectId] && projectPageMap[projectId][pageId]) {
return projectPageMap[projectId][pageId];
} else if (projectArchivedPageMap[projectId] && projectArchivedPageMap[projectId][pageId]) {
return projectArchivedPageMap[projectId][pageId];
} else {
if (!projectId || !workspaceSlug) {
console.log("usePage must be used within ProjectProvider");
return;
}
if (projectPageMap[projectId] && projectPageMap[projectId][pageId]) return projectPageMap[projectId][pageId];
else if (projectArchivedPageMap[projectId] && projectArchivedPageMap[projectId][pageId])
return projectArchivedPageMap[projectId][pageId];
else return;
};