diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index bfc35fd..4d74dbe 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -40,13 +40,6 @@ - - - diff --git a/frontend/src/components/routing/ViewSetRouter.tsx b/frontend/src/components/routing/ViewSetRouter.tsx index b8b9b04..d6cf085 100644 --- a/frontend/src/components/routing/ViewSetRouter.tsx +++ b/frontend/src/components/routing/ViewSetRouter.tsx @@ -24,37 +24,44 @@ export function ViewSetRouter({viewSet, unselec const path = useSophonPath() const pk = path?.[pathSegment] - if(viewSet === undefined) { - return ( - - - - ) - } + return React.useMemo( + () => { + if(viewSet === undefined) { + return ( + + + + ) + } - // If an error happens, display it in a ErrorBox - if(viewSet.error) { - return ( - - ) - } + // If an error happens, display it in a ErrorBox + if(viewSet.error) { + return ( + + ) + } - // If the viewset is still loading, display a loading message - if(viewSet.resources === null) { - return ( - - - - ) - } + // If the viewset is still loading, display a loading message + if(viewSet.resources === null) { + return ( + + + + ) + } - const selection = pk ? viewSet.resources?.find(res => res.value[pkKey] === pk) : undefined + const selection = pk ? viewSet.resources?.find(res => res.value[pkKey] === pk) : undefined - return ( - } - selectedRoute={(props) => } - /> + return ( + } + selectedRoute={(props) => } + /> + ) + }, + [viewSet, UnselectedRoute, SelectedRoute, pk, pkKey], ) + + } diff --git a/frontend/src/hooks/useManagedViewSet.ts b/frontend/src/hooks/useManagedViewSet.ts index dbc282c..8a76f7f 100644 --- a/frontend/src/hooks/useManagedViewSet.ts +++ b/frontend/src/hooks/useManagedViewSet.ts @@ -617,17 +617,22 @@ export function useManagedViewSet(baseRoute: st [refresh, state, refreshOnMount, viewset, baseRoute], ) - if(!viewset) { - return undefined - } + return React.useMemo( + () => { + if(!viewset) { + return undefined + } - return { - busy: state.busy, - error: state.error, - operationError: state.operationError, - resources, - refresh, - create, - command, - } + return { + busy: state.busy, + error: state.error, + operationError: state.operationError, + resources, + refresh, + create, + command, + } + }, + [state, resources, refresh, create, command] + ) } diff --git a/frontend/src/hooks/useViewSet.ts b/frontend/src/hooks/useViewSet.ts index 14d5f6b..12baa28 100644 --- a/frontend/src/hooks/useViewSet.ts +++ b/frontend/src/hooks/useViewSet.ts @@ -149,9 +149,15 @@ export function useViewSet(baseRoute: string): ViewSet | und [action, baseRoute], ) - if(!api) { - return undefined - } - return {command, action, list, retrieve, create, update, destroy} + return React.useMemo( + () => { + if(!api) { + return undefined + } + + return {command, action, list, retrieve, create, update, destroy} + }, + [command, action, list, retrieve, create, update, destroy], + ) }