fumadocs-core
Version:
The React.js library for building a documentation website
69 lines (66 loc) • 1.74 kB
JavaScript
'use client';
import { createContext, use, useMemo } from "react";
import { jsx } from "react/jsx-runtime";
//#region src/framework/index.tsx
const notImplemented = () => {
throw new Error("You need to wrap your application inside `FrameworkProvider`.");
};
const FrameworkContext = createContext({
useParams: notImplemented,
useRouter: notImplemented,
usePathname: notImplemented
});
function FrameworkProvider({ Link: Link$1, useRouter: useRouter$1, useParams: useParams$1, usePathname: usePathname$1, Image: Image$1, children }) {
return /* @__PURE__ */ jsx(FrameworkContext, {
value: useMemo(() => ({
usePathname: usePathname$1,
useRouter: useRouter$1,
Link: Link$1,
Image: Image$1,
useParams: useParams$1
}), [
Link$1,
usePathname$1,
useRouter$1,
useParams$1,
Image$1
]),
children
});
}
function usePathname() {
return use(FrameworkContext).usePathname();
}
function useRouter() {
return use(FrameworkContext).useRouter();
}
function useParams() {
return use(FrameworkContext).useParams();
}
function Image(props) {
const { Image: Image$1 } = use(FrameworkContext);
if (!Image$1) {
const { src, alt, priority, ...rest } = props;
return /* @__PURE__ */ jsx("img", {
alt,
src,
fetchPriority: priority ? "high" : "auto",
...rest
});
}
return /* @__PURE__ */ jsx(Image$1, { ...props });
}
function Link(props) {
const { Link: Link$1 } = use(FrameworkContext);
if (!Link$1) {
const { href, prefetch: _, ...rest } = props;
return /* @__PURE__ */ jsx("a", {
href,
...rest
});
}
return /* @__PURE__ */ jsx(Link$1, { ...props });
}
//#endregion
export { FrameworkProvider, Image, Link, useParams, usePathname, useRouter };
//# sourceMappingURL=index.js.map