UNPKG

fastapi-rtk

Version:

A React component library for FastAPI in combination with FastAPI React Toolkit backend, built with Mantine, JsonForms, and Zustand.

34 lines (33 loc) 2.09 kB
import { jsx } from "react/jsx-runtime"; import { useProxy } from "fastapi-rtk/zustand"; import { QueryClient } from "../../../../.external/esm/@tanstack_query-core@5.89.0/@tanstack/query-core/build/modern/queryClient.mjs"; import { QueryClientProvider } from "../../../../.external/esm/@tanstack_react-query@5.89.0_react@18.3.1/@tanstack/react-query/build/modern/QueryClientProvider.mjs"; import { useState, useMemo } from "react"; import { defaultAuth } from "../../fab-react-toolkit-patch/auth/hooks/useProvideAuth.mjs"; import { defaultInfo } from "../../fab-react-toolkit-patch/auth/hooks/useProvideInfo.mjs"; import { AuthContextProvider } from "./Contexts/AuthContext.mjs"; import { InfoContextProvider } from "./Contexts/InfoContext.mjs"; import { LangContextProvider } from "./Contexts/LangContext.mjs"; import { useProvideAuth } from "./hooks/useProvideAuth.mjs"; import { useProvideInfo } from "./hooks/useProvideInfo.mjs"; function InnerProvider(props) { const defaultproviderProps = { baseUrl: new URL(document.baseURI).pathname + "/api/v1", inheritMantineTheme: false }; const { baseUrl, authQueryProps, children } = { ...defaultproviderProps, ...props }; const { authParams, infoParams } = useMemo( () => props.fab ? { authParams: defaultAuth, infoParams: defaultInfo } : {}, [props.fab] //* Backward compatibility to fab-react-toolkit ); const auth = useProvideAuth(baseUrl, authQueryProps, authParams); const authProxy = useProxy(auth); const info = useProvideInfo(baseUrl, auth, infoParams); const infoProxy = useProxy(info); return /* @__PURE__ */ jsx(AuthContextProvider, { value: authProxy, children: /* @__PURE__ */ jsx(InfoContextProvider, { value: infoProxy, children: /* @__PURE__ */ jsx(LangContextProvider, { langProps: props.langProps, children }) }) }); } const Provider = (props) => { const [queryClient] = useState(() => new QueryClient(props.queryClientProps)); return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx(InnerProvider, { ...props }) }); }; export { Provider };