@atlaskit/breadcrumbs
Version:
Breadcrumbs are a navigation system used to show a user's location in a site or app.
25 lines • 857 B
JavaScript
import { useEffect } from 'react';
import usePreviousValue from '@atlaskit/ds-lib/use-previous-value';
/**
* The hook is used to invoke callback after breadcrumbs is revealed.
*
* The hook checks if previous state of breadcrumbs was collapsed and current state is expanded
* and if so invoke received callback.
*
* @param callback the function to invoke after revealing
* @param param1 the object that contain two field:
* 1) isExpanded - current state of breadcrumbs
* 2) isDisabled - to disable the callback.
*/
export function useOnRevealed(callback, {
isExpanded,
isDisabled
}) {
const prevExtended = usePreviousValue(isExpanded);
useEffect(() => {
const hasBeenRevealed = !prevExtended && isExpanded;
if (!isDisabled && hasBeenRevealed) {
callback();
}
}, [isExpanded, isDisabled, callback, prevExtended]);
}