From c4028efd7126046a7573560ea0c61605b614a01b Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Wed, 28 Feb 2024 19:14:15 +0530 Subject: [PATCH] fix: usePage hook throws an error without projectId (#3827) --- web/hooks/store/use-page.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/web/hooks/store/use-page.ts b/web/hooks/store/use-page.ts index 8971acd22..2d4dbd5b1 100644 --- a/web/hooks/store/use-page.ts +++ b/web/hooks/store/use-page.ts @@ -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; };