From a133501237cc413896c8956fe84ded63b52610aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Zaninotto?= Date: Wed, 6 Nov 2024 08:45:12 +0100 Subject: [PATCH] Fix double log of AdminGuesser --- packages/demo/src/index.tsx | 6 +++++- .../src/guessers/useCrudGuesser.tsx | 12 +++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) 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]); };