From 9f3651c2339652c76ba18ab6266cdd162d7b5c0e Mon Sep 17 00:00:00 2001 From: xiaohuoni Date: Thu, 21 Sep 2023 09:36:57 +0800 Subject: [PATCH] fix: emitter subscription error --- .changeset/slimy-chairs-perform.md | 5 +++++ packages/plugins/templates/mobile-layout/layout.tpl | 10 ++++++---- packages/plugins/templates/mobile-layout/layout5.tpl | 10 ++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 .changeset/slimy-chairs-perform.md diff --git a/.changeset/slimy-chairs-perform.md b/.changeset/slimy-chairs-perform.md new file mode 100644 index 00000000..8b120385 --- /dev/null +++ b/.changeset/slimy-chairs-perform.md @@ -0,0 +1,5 @@ +--- +'@alita/plugins': patch +--- + +fix: useEffets error diff --git a/packages/plugins/templates/mobile-layout/layout.tpl b/packages/plugins/templates/mobile-layout/layout.tpl index 822fe9f0..40645d8e 100644 --- a/packages/plugins/templates/mobile-layout/layout.tpl +++ b/packages/plugins/templates/mobile-layout/layout.tpl @@ -448,10 +448,12 @@ const BasicLayout: React.FC = (props) => { prevPathName = location.pathname; }, 10); }, [location.pathname]); - layoutEmitter?.useSubscription?.((e) => { - setPageNavBar(getPageNavBar()); - setTabBarList(getTabBarList()); - }); + useEffect(()=>{ + layoutEmitter?.useSubscription?.((e) => { + setPageNavBar(getPageNavBar()); + setTabBarList(getTabBarList()); + }); + },[]); let element = useOutlet(); {{#hasKeepAlive}} element = useKeepOutlets(); diff --git a/packages/plugins/templates/mobile-layout/layout5.tpl b/packages/plugins/templates/mobile-layout/layout5.tpl index ec91f2b5..3a9b66e7 100644 --- a/packages/plugins/templates/mobile-layout/layout5.tpl +++ b/packages/plugins/templates/mobile-layout/layout5.tpl @@ -434,10 +434,12 @@ const BasicLayout: React.FC = (props) => { prevPathName = location.pathname; }, 10); }, [location.pathname]); - layoutEmitter?.useSubscription?.((e) => { - setPageNavBar(getPageNavBar()); - setTabBarList(getTabBarList()); - }); + useEffect(()=>{ + layoutEmitter?.useSubscription?.((e) => { + setPageNavBar(getPageNavBar()); + setTabBarList(getTabBarList()); + }); + },[]); let element = useOutlet(); {{#hasKeepAlive}} element = useKeepOutlets();