Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request #14 from siriwatknp/develop
Browse files Browse the repository at this point in the history
fix bug rules-of-hooks
  • Loading branch information
siriwatknp authored Jul 17, 2019
2 parents a3678f3 + a31396d commit 387474d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
29 changes: 15 additions & 14 deletions src/hooks/useAutoCollapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ export default () => {
autoCollapsedDisabled,
} = useConfig();

if (autoCollapsedDisabled) {
return null;
}

useEffect(() => {
if (collapsible && screen) {
if (collapsed && screen === collapsedBreakpoint) {
setCollapsed(false);
}
if (
!collapsed &&
keys.indexOf(screen) < keys.indexOf(collapsedBreakpoint)
) {
setCollapsed(true);
// skip everything if user disable this feature in config
if (!autoCollapsedDisabled) {
if (collapsible && screen) {
if (collapsed && screen === collapsedBreakpoint) {
setCollapsed(false);
}
if (
!collapsed &&
keys.indexOf(screen) < keys.indexOf(collapsedBreakpoint)
) {
setCollapsed(true);
}
}
}
}, [screen]);

if (autoCollapsedDisabled) {
return null;
}
return true;
};
19 changes: 9 additions & 10 deletions src/hooks/useHeightAdjustment.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ export default (appBarHeight, interval) => {
const getScreenValue = createGetScreenValue(keys, currentScreen);
const initialHeight = getScreenValue(appBarHeight, initialAdjustmentHeight);

if (heightAdjustmentDisabled) return 0; // disabled by user.
if (navVariant === 'temporary') return 0;
if (!clipped) {
// do not run the effect below if behavior is not right.
return 0;
}
if (clipped && someIs(['sticky', 'fixed'], headerPosition)) {
return initialHeight;
}

const [height, setHeight] = useState(initialHeight);
const debounced = useRef(() =>
setTimeout(() => {
Expand All @@ -46,5 +36,14 @@ export default (appBarHeight, interval) => {
window.removeEventListener('scroll', debounced.current);
};
}, []);
if (heightAdjustmentDisabled) return 0; // disabled by user.
if (navVariant === 'temporary') return 0;
if (!clipped) {
// do not run the effect below if behavior is not right.
return 0;
}
if (clipped && someIs(['sticky', 'fixed'], headerPosition)) {
return initialHeight;
}
return height;
};

0 comments on commit 387474d

Please sign in to comment.