Skip to content

Commit

Permalink
try this
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed May 14, 2022
1 parent 58df297 commit 33d423c
Showing 1 changed file with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React, {
type ComponentProps,
useEffect,
useMemo,
useCallback,
} from 'react';
import React, {type ComponentProps, useEffect, useMemo} from 'react';
import clsx from 'clsx';
import {
isActiveSidebarItem,
Expand Down Expand Up @@ -133,13 +128,10 @@ export default function DocSidebarItemCategory({

const {expandedItem, setExpandedItem} = useDocSidebarItemsExpandedState();
// Use this instead of `setCollapsed`, because it is also reactive
const updateCollapsed = useCallback(
(toCollapsed: boolean) => {
setExpandedItem(toCollapsed ? null : index);
setCollapsed(toCollapsed);
},
[index, setCollapsed, setExpandedItem],
);
const updateCollapsed = (toCollapsed: boolean = !collapsed) => {
setExpandedItem(toCollapsed ? null : index);
setCollapsed(toCollapsed);
};
useAutoExpandActiveCategory({isActive, collapsed, updateCollapsed});
useEffect(() => {
if (
Expand All @@ -148,16 +140,9 @@ export default function DocSidebarItemCategory({
expandedItem !== index &&
autoCollapseCategories
) {
updateCollapsed(true);
setCollapsed(true);
}
}, [
collapsible,
expandedItem,
index,
updateCollapsed,
setExpandedItem,
autoCollapseCategories,
]);
}, [collapsible, expandedItem, index, setCollapsed, autoCollapseCategories]);

return (
<li
Expand Down Expand Up @@ -188,7 +173,7 @@ export default function DocSidebarItemCategory({
updateCollapsed(false);
} else {
e.preventDefault();
updateCollapsed(!collapsed);
updateCollapsed();
}
}
: () => {
Expand All @@ -206,7 +191,7 @@ export default function DocSidebarItemCategory({
categoryLabel={label}
onClick={(e) => {
e.preventDefault();
updateCollapsed(!collapsed);
updateCollapsed();
}}
/>
)}
Expand Down

0 comments on commit 33d423c

Please sign in to comment.