Skip to content

Commit

Permalink
created client-side loading crypto providers
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-defi committed Nov 8, 2024
1 parent 142582c commit 8f688f0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions apps/web/app/CryptoProviders.dynamic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use client';

import { useEffect, useState } from 'react';
import { useErrors } from 'apps/web/contexts/Errors';

// RigidBody cannot be imported using dynamic() due to some import issues
export function DynamicCryptoProviders({ children }: { children: React.ReactNode }) {
const [CryptoProvidersDynamic, setCryptoProvidersDynamic] = useState<React.ComponentType<{ children: React.ReactNode }>>();
const { logError } = useErrors();

// Import needs to happens on render
useEffect(() => {
import('apps/web/app/CryptoProviders')
.then((mod) => {
setCryptoProvidersDynamic(() => mod.default);
})
.catch((error) => logError(error, 'Failed to load CryptoProviders'));
}, [logError]);

if (!CryptoProvidersDynamic) return null;

return <CryptoProvidersDynamic>{children}</CryptoProvidersDynamic>;
}

0 comments on commit 8f688f0

Please sign in to comment.