refactor: follow correct react rules (#3119)

This commit is contained in:
Alex Yang
2023-07-10 18:32:15 +08:00
committed by GitHub
parent 2f910fbad0
commit 6caf934d47
7 changed files with 60 additions and 84 deletions
+20 -12
View File
@@ -214,20 +214,28 @@ export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
//#endregion
//#region check if page is valid
if (
typeof router.query.pageId === 'string' &&
router.pathname === '/workspace/[workspaceId]/[pageId]' &&
currentPageId
) {
if (currentPageId !== router.query.pageId) {
setCurrentPageId(router.query.pageId);
} else {
const page = currentWorkspace.blockSuiteWorkspace.getPage(currentPageId);
if (!page) {
router.push('/404').catch(console.error);
useEffect(() => {
if (
typeof router.query.pageId === 'string' &&
router.pathname === '/workspace/[workspaceId]/[pageId]' &&
currentPageId
) {
if (currentPageId !== router.query.pageId) {
setCurrentPageId(router.query.pageId);
} else {
const page =
currentWorkspace.blockSuiteWorkspace.getPage(currentPageId);
if (!page) {
router.push('/404').catch(console.error);
}
}
}
}
}, [
currentPageId,
currentWorkspace.blockSuiteWorkspace,
router,
setCurrentPageId,
]);
//#endregion
usePassiveWorkspaceEffect(currentWorkspace.blockSuiteWorkspace);