@atlaskit/side-navigation
Version:
A highly composable side navigation component that supports nested views.
17 lines • 743 B
JavaScript
import { useEffect, useRef } from 'react';
import { ROOT_ID } from '../components/NestableNavigationContent';
const useChildIds = (currentStackId, committedStack, onUnknownNest) => {
const childIdsRef = useRef(new Set());
useEffect(() => {
// we are holding navigation item IDs in childIdsRef
// check if the current displayed nav item (currentStackId) is in childIdsRef. if it's not, this means it's undefined
if (currentStackId === ROOT_ID || !childIdsRef.current.size || childIdsRef.current.has(currentStackId) || !onUnknownNest) {
return;
}
onUnknownNest(committedStack || [currentStackId]);
}, [currentStackId, committedStack, onUnknownNest]);
return {
childIdsRef
};
};
export default useChildIds;