mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 21:15:18 +09:00
18 lines
550 B
TypeScript
18 lines
550 B
TypeScript
import { Instance } from "@webstudio-is/sdk";
|
|
import { useMemo } from "react";
|
|
import { getInstancePath } from "~/shared/tree-utils";
|
|
import { useRootInstance } from "../nano-values";
|
|
|
|
export const useSelectedInstancePath = (
|
|
selectedInstanceId?: Instance["id"]
|
|
): Array<Instance> => {
|
|
const [rootInstance] = useRootInstance();
|
|
return useMemo(
|
|
() =>
|
|
selectedInstanceId !== undefined && rootInstance !== undefined
|
|
? getInstancePath(rootInstance, selectedInstanceId)
|
|
: [],
|
|
[selectedInstanceId, rootInstance]
|
|
);
|
|
};
|