UNPKG

@base-ui/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

29 lines (27 loc) 877 B
'use client'; import * as React from 'react'; import { useStableCallback } from '@base-ui/utils/useStableCallback'; import { useAnimationsFinished } from "./useAnimationsFinished.js"; /** * Calls the provided function when the CSS open/close animation or transition completes. */ export function useOpenChangeComplete(parameters) { const { enabled = true, open, ref, onComplete: onCompleteParam } = parameters; const onComplete = useStableCallback(onCompleteParam); const runOnceAnimationsFinish = useAnimationsFinished(ref, open, false); React.useEffect(() => { if (!enabled) { return undefined; } const abortController = new AbortController(); runOnceAnimationsFinish(onComplete, abortController.signal); return () => { abortController.abort(); }; }, [enabled, open, onComplete, runOnceAnimationsFinish]); }