mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
* base menu works * action internal link & group * action external link * simplify NewTemplatesMenu * animation * tiny cleanup * simplify group api * icon spacer * root action * mobile menu * decrease drawer animation speed * format * animation, const separator * memo.. * TemplatesMenu + Scrollable dropdown * delete file-ops * cap height
27 lines
716 B
TypeScript
27 lines
716 B
TypeScript
import isEqual from "lodash/isEqual";
|
|
import { useRef } from "react";
|
|
import { createRootMenuAction } from "~/actions";
|
|
import {
|
|
ActionV2Group,
|
|
ActionV2Separator,
|
|
ActionV2Variant,
|
|
ActionV2WithChildren,
|
|
} from "~/types";
|
|
import usePrevious from "./usePrevious";
|
|
|
|
type Actions = (ActionV2Variant | ActionV2Group | ActionV2Separator)[];
|
|
|
|
export function useMenuAction(actions: Actions) {
|
|
const rootActionRef = useRef<ActionV2WithChildren>(
|
|
createRootMenuAction(actions)
|
|
);
|
|
const prevActions = usePrevious(actions);
|
|
|
|
if (!prevActions || isEqual(actions, prevActions)) {
|
|
return rootActionRef.current;
|
|
}
|
|
|
|
rootActionRef.current = createRootMenuAction(actions);
|
|
return rootActionRef.current;
|
|
}
|