diff --git a/packages/demo/src/index.tsx b/packages/demo/src/index.tsx index 9c5a09f..d788cab 100644 --- a/packages/demo/src/index.tsx +++ b/packages/demo/src/index.tsx @@ -4,7 +4,11 @@ import App from './App'; import reportWebVitals from './reportWebVitals'; const root = createRoot(document.getElementById('root') as HTMLElement); -root.render(); +root.render( + + + +); // If you want to start measuring performance in your app, pass a function // to log results (for example: reportWebVitals(console.log)) diff --git a/packages/ra-supabase-ui-materialui/src/guessers/useCrudGuesser.tsx b/packages/ra-supabase-ui-materialui/src/guessers/useCrudGuesser.tsx index 8811b78..80ded4f 100644 --- a/packages/ra-supabase-ui-materialui/src/guessers/useCrudGuesser.tsx +++ b/packages/ra-supabase-ui-materialui/src/guessers/useCrudGuesser.tsx @@ -1,3 +1,4 @@ +import { useMemo } from 'react'; import { useAPISchema } from 'ra-supabase-core'; import type { ResourceProps } from 'react-admin'; @@ -8,11 +9,13 @@ import { ShowGuesser } from './ShowGuesser'; export const useCrudGuesser = () => { const { data: schema, error, isPending } = useAPISchema(); - let resourceDefinitions: ResourceProps[] = []; - if (!isPending && !error) { + return useMemo(() => { + if (isPending || error) { + return []; + } let edit, show, create, list; const resourceNames = Object.keys(schema.definitions!); - resourceDefinitions = resourceNames.map(name => { + return resourceNames.map(name => { const resourcePaths = schema.paths[`/${name}`] ?? {}; if (resourcePaths.get) { list = ListGuesser; @@ -32,6 +35,5 @@ export const useCrudGuesser = () => { create, }; }); - } - return resourceDefinitions; + }, [schema, isPending, error]); };