UNPKG

@atlaskit/side-navigation

Version:

A highly composable side navigation component that supports nested views.

17 lines • 775 B
import { useEffect, useRef } from 'react'; import { ROOT_ID } from '../components/NestableNavigationContent'; var useChildIds = function useChildIds(currentStackId, committedStack, onUnknownNest) { var childIdsRef = useRef(new Set()); useEffect(function () { // 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: childIdsRef }; }; export default useChildIds;