Files
outline/app/hooks/useMenuAction.ts
T
ZhuoYang Wu(阿离)andTom Moor 19da56c2c7 Improve sidebar menu and navigation tree performance (#12873)
* Improve sidebar menu and navigation tree performance

* remote some test and rollback useOnScreen

* feat: introduce ActionFactory type and update context menu components to support it

- Added ActionFactory type to allow functions returning ActionWithChildren.
- Updated ContextMenu and DropdownMenu components to handle ActionFactory.
- Modified DocumentRow, SidebarLink, and other components to accept ActionFactory for context actions.
- Refactored useDocumentMenuAction to utilize createRootMenuAction for better action management.

---------

Co-authored-by: Tom Moor <tom@getoutline.com>
2026-07-18 12:01:35 -04:00

30 lines
805 B
TypeScript

import { isEqual } from "es-toolkit/compat";
import { useRef } from "react";
import { createRootMenuAction } from "~/actions";
import type {
ActionGroup,
ActionSeparator,
ActionVariant,
ActionWithChildren,
} from "~/types";
import usePrevious from "./usePrevious";
type Actions = (ActionVariant | ActionGroup | ActionSeparator)[];
export function useMenuAction(actions: Actions) {
const rootActionRef = useRef<ActionWithChildren>();
const prevActions = usePrevious(actions);
if (!rootActionRef.current) {
rootActionRef.current = createRootMenuAction(actions);
return rootActionRef.current;
}
if (!prevActions || isEqual(actions, prevActions)) {
return rootActionRef.current;
}
rootActionRef.current = createRootMenuAction(actions);
return rootActionRef.current;
}