Skip to content

Commit

Permalink
fix: fix previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
satazor committed Aug 24, 2020
1 parent eec2276 commit 760c960
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/with-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
10 changes: 6 additions & 4 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ exports[`should not update layout if page is not the active Component of LayoutT
</WithLayout(Home)>
</main>
</PrimaryLayout>
<WithLayout(Home)>
<Home>
<WithLayout(Foo)>
<Foo
setLayoutState={[Function]}
>
<h1>
Home
</h1>
</Home>
</WithLayout(Home)>
</Foo>
</WithLayout(Foo)>
</LayoutTree>
`;

Expand Down
12 changes: 10 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <h1>Home</h1>;
};

const EnhancedHome = withLayout(<PrimaryLayout />)(Home);
const AnotherEnhancedHome = withLayout(<SecondaryLayout />)(Home);
const EnhancedFoo = withLayout(() => <SecondaryLayout />)(Foo);

const render = jest.fn((tree) => (
<>
{ tree }
{ <AnotherEnhancedHome /> }
{ <EnhancedFoo /> }
</>
));

Expand Down

0 comments on commit 760c960

Please sign in to comment.