From 3a5cd0ae32d053da36f5b86578ddc37d35d95dde Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 21 Mar 2024 15:32:39 -0400 Subject: [PATCH] refactor: split app to App and Root and store the sdk context in the root for app to use --- app/root.tsx | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/app/root.tsx b/app/root.tsx index 26300e4..6d099b6 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -7,15 +7,16 @@ import type {LinksFunction} from "@remix-run/node"; import '@fontsource-variable/manrope'; import {Refine} from "@refinedev/core"; import routerProvider from "@refinedev/remix-router"; -import { notificationProvider } from "~/data/notification-provider"; -import {SdkContextProvider} from "~/components/lib/sdk-context"; -import { Toaster } from "~/components/ui/toaster"; +import {notificationProvider} from "~/data/notification-provider"; +import {SdkContextProvider, useSdk} from "~/components/lib/sdk-context"; +import {Toaster} from "~/components/ui/toaster"; import {getProviders} from "~/data/providers.js"; import {Sdk} from "@lumeweb/portal-sdk"; import resources from "~/data/resources.js"; +import {useMemo} from "react"; export const links: LinksFunction = () => [ - { rel: "stylesheet", href: stylesheet }, + {rel: "stylesheet", href: stylesheet}, ]; export function Layout({children}: { children: React.ReactNode }) { @@ -29,7 +30,7 @@ export function Layout({children}: { children: React.ReactNode }) { {children} - + @@ -37,9 +38,9 @@ export function Layout({children}: { children: React.ReactNode }) { ); } -export default function App() { - const sdk = Sdk.create(import.meta.env.VITE_PORTAL_URL) - const providers = getProviders(sdk); +function App() { + const sdk = useSdk(); + const providers = useMemo(() => getProviders(sdk as Sdk), [sdk]); return ( - - - + ); } +export default function Root() { + const sdk = Sdk.create(import.meta.env.VITE_PORTAL_URL) + return ( + + + + ); +} + export function HydrateFallback() { return

Loading...

; }