From 760c9609eed89451717e0c2a803cc9d59446127f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Mon, 24 Aug 2020 14:41:34 +0100 Subject: [PATCH] fix: fix previous commit --- src/with-layout.js | 2 +- test/__snapshots__/index.test.js.snap | 10 ++++++---- test/index.test.js | 12 ++++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/with-layout.js b/src/with-layout.js index dd50ac1..690b14c 100644 --- a/src/with-layout.js +++ b/src/with-layout.js @@ -32,7 +32,7 @@ const withLayout = (mapLayoutStateToLayoutTree, mapPropsToInitialLayoutState) => const [layoutState, setLayoutState] = useObjectState(initialLayoutStateRef.current); useEffect(() => { - if (layoutState !== initialLayoutStateRef.current) { + if (layoutState !== initialLayoutStateRef.current && ProviderComponent === WithLayout) { updateLayoutTree(mapLayoutStateToLayoutTree(layoutState)); } }, [layoutState, updateLayoutTree, ProviderComponent]); diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index ca25daf..b01275f 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -62,13 +62,15 @@ exports[`should not update layout if page is not the active Component of LayoutT - - + +

Home

-
-
+ + `; diff --git a/test/index.test.js b/test/index.test.js index 46e1c3e..da04721 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -225,13 +225,21 @@ it('should fail if LayoutTree was not rendered', () => { it('should not update layout if page is not the active Component of LayoutTree', () => { jest.spyOn(console, 'error').mockImplementation(() => {}); + const Foo = ({ setLayoutState }) => { + useEffect(() => { + setLayoutState({ variant: 'dark' }); + }, [setLayoutState]); + + return

Home

; + }; + const EnhancedHome = withLayout()(Home); - const AnotherEnhancedHome = withLayout()(Home); + const EnhancedFoo = withLayout(() => )(Foo); const render = jest.fn((tree) => ( <> { tree } - { } + { } ));