import { useMemo, useEffect, useSyncExternalStore } from "react";
import { useResourceResolver } from "./use-resource-resolver";
import { propErrorHandlingProxy } from "../utils/prop-error-handling-proxy";
function useResolvedValue(data, resolver, defaultValue) {
  const resourceResolver = useResourceResolver();
  const resolvable = useMemo(() => {
    return propErrorHandlingProxy(resolver(data, resourceResolver), defaultValue, (error) => {
      console.warn(`Error resolving data, falling back to \`${defaultValue}\`.`, { error, data });
    });
  }, [data, resourceResolver, defaultValue]);
  useEffect(() => {
    resolvable.triggerResolve();
  }, [resolvable]);
  return useSyncExternalStore(resolvable.subscribe, resolvable.readStable, resolvable.readStable);
}
export {
  useResolvedValue
};
//# sourceMappingURL=use-resolved-value.js.map