You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
862 B
31 lines
862 B
import type { Container, ContainerUri } from "@ldo/solid";
|
|
import { useEffect, useState } from "react";
|
|
import type { UseResourceOptions } from "./useResource";
|
|
import { useResource } from "./useResource";
|
|
import { useLdo } from "./SolidLdoProvider";
|
|
|
|
export function useRootContainerFor(
|
|
uri?: string,
|
|
options?: UseResourceOptions,
|
|
): Container | undefined {
|
|
const { getResource } = useLdo();
|
|
|
|
const [rootContainerUri, setRootContainerUri] = useState<
|
|
ContainerUri | undefined
|
|
>(undefined);
|
|
|
|
useEffect(() => {
|
|
if (uri) {
|
|
const givenResource = getResource(uri);
|
|
givenResource.getRootContainer().then((result) => {
|
|
if (!result.isError) {
|
|
setRootContainerUri(result.uri);
|
|
}
|
|
});
|
|
} else {
|
|
setRootContainerUri(undefined);
|
|
}
|
|
}, [uri]);
|
|
|
|
return useResource(rootContainerUri, options);
|
|
}
|
|
|